rm(list=ls())


#WORKING DIRECTORY DATA
#SET WORKING DIRECTORY HERE


####################
#PACKAGES NEEDED   #
####################
#install.packages("arm")
library(arm)
#install.packages("sandwich")
#install.packages("doBy")
library("doBy")
library(sandwich)
#install.packages("xtable")
library(xtable)
#library(Zelig)
#library("lme4")
#library(robust)
#library(vcd)
#install.packages("foreign")
library(foreign)
#install.packages("gplots")
library(gplots)
library(ggpubr)

#install.packages("car")
library(car)
#install.packages("plm")
library(plm)
library(MASS)
library(Zelig)
library(foreign)
library(xtable)
#install.packages("xtable")
#install.packages("car")
library(car)
library(ggplot2)
library(gplots)
library(foreign)
library(stargazer)
#install.packages("survey")
library(survey)

require(foreign)
require(nnet)
require(ggplot2)
require(reshape2)



data_full<-read.dta("ESS1-7e01.dta")


###############
#DATA CREATION##
################

#selecting variables to do an rbind with the 8th wave.
#names(data_full)

data1_7<-data_full[, c("idno","cntry", "essround", "dweight", "pspwght", "pweight", "tvtot", "tvpol", "nwsppol", "netuse", "ppltrst", "polintr", "trstprl", "trstlgl", "trstplc", "trstplt", "trstprt", "trstep", "trstun", "vote", "contplt", "wrkprty", "sgnptit", "clsprty", "lrscale", "stflife", "stfeco", "stfgov","stfdem", "stfedu", "happy", "sclmeet", "sclact", "crmvct", "health", "rlgblg", "rlgdnm", "rlgdgr", "rlgatnd", "dscrgrp", "ctzcntr", "ctzship", "ctzshipa", "ctzshipb", "ctzshipc", "brncntr", "livecntr", "livecnta", "hhmmb", "gndr", "yrbrn", "agea", "chldhm", "eduyrs", "pdwrk", "imptrad", "inwyr", "inwyye", "hinctnt", "hinctnta", "lnghoma", "lnghom1", "facntr", "mocntr", "fbrncnt","fbrncnta", "fbrncntb", "mbrncnt", "mbrncnta", "mbrncntb", "rship2", "rshipa2", "rship3", "rshipa3", "partner" , "cregion",  "regunit",  "regionat", "regionbe", "regionbg" ,"regionch", "regioach" ,"regioncy" ,"regioncz", "regioacz", "regionde", "regiondk", "regioadk" ,"regionee", "regiones", "regioaes" , "regionfi" , "regioafi", "regionfr", "regiongb", "regiongr", "regioagr", "regionhr" ,"regionhu", "regionie", "regioaie", "regiobie", "regionil", "regionit", "regionlu", "regionnl", "regionno" , "regionpl", "regionpt" , "regioapt", "regionru", "regionse", "regionsi", "regionsk", "regiontr" ,"regionua", "inwdd", "inwdds", "inwdde", "inwmm", "inwmms", "inwmme", "impfree",  "pplfair", "pbldmn", "badge", "inwyr", "inwyys", "inwyye",
#which party close to?
"prtclat",  "prtclaat",  "prtclcat",
"prtclbe",  "prtclabe", "prtclbbe", "prtclcbe",
"prtclbg" , "prtclabg", "prtclbbg", "prtclcbg",
"prtclch",  "prtclach", "prtclbch", "prtclcch", "prtcldch", "prtclech",
"prtclcy",  "prtclacy",
"prtclcz",  "prtclacz", "prtclbcz", "prtclccz", "prtcldcz",
"prtclde" , "prtclade", "prtclbde", "prtclcde", "prtcldde", "prtclede",
"prtcldk",  "prtcladk", "prtclbdk", "prtclcdk",
"prtclee",  "prtclaee", "prtclbee", "prtclcee", "prtcldee", "prtcleee",
"prtcles",  "prtclaes", "prtclbes","prtclces", "prtcldes",
"prtclfi",  "prtclafi", "prtclbfi", "prtclcfi", 
"prtclfr",  "prtclafr", "prtclbfr", "prtclcfr", "prtcldfr",
"prtclgb",  "prtclagb", "prtclbgb",
"prtclgr",  "prtclagr" ,"prtclbgr", "prtclcgr",
"prtclhr",
"prtclhu",  "prtclahu", "prtclbhu", "prtclchu", "prtcldhu", "prtclehu",
"prtclie",  "prtclaie","prtclbie",
"prtclil",  "prtclail", "prtclbil", "prtclcil", "prtcldil",
"prtclis",  "prtclais", 
"prtclit", "prtclait", "prtclbit",
"prtcllu",
"prtcllt",  "prtclalt",
"prtclnl",  "prtclanl", "prtclbnl", "prtclcnl", "prtcldnl", "prtclenl",
"prtclno",  "prtclano", "prtclbno",
"prtclpl",  "prtclapl", "prtclbpl", "prtclcpl","prtcldpl", "prtclepl", "prtclfpl", 
"prtclpt", "prtclapt", "prtclbpt", "prtclcpt", "prtcldpt",
"prtclru", "prtclaru", "prtclbru", "prtclcru",
"prtclse",  "prtclase", "prtclbse",
"prtclsi",  "prtclasi", "prtclbsi", "prtclcsi", "prtcldsi", "prtclesi",
 "prtclsk",  "prtclask", "prtclbsk", "prtclcsk",
"prtcltr",  "prtclatr",
"prtclua" , "prtclaua", "prtclbua", "prtclcua", "prtcldua", "rdpol", "nwsppol", "rlgdnm"
)]



#SET here DIRECTORY FOR THE OTHER DATA FROM ESS WAVE 8
data8_full<-read.dta("ESS8e02.dta")

data8_full$placeholder<-rep(NA, rep(nrow(data8_full)))


data8_full$essround1<-rep("8", nrow(data8_full))
data8<-data8_full[, c("idno","cntry", "essround1", "dweight", "pspwght", "pweight", "placeholder", "placeholder", "nwspol", "placeholder", "ppltrst", "polintr", "trstprl", "trstlgl", "trstplc", "trstplt", "trstprt", "trstep", "trstun", "vote", "contplt", "wrkprty", "sgnptit", "clsprty", "lrscale", "stflife", "stfeco", "stfgov","stfdem", "stfedu", "happy", "sclmeet", "sclact", "crmvct", "health", "rlgblg", "rlgdnm", "rlgdgr", "rlgatnd", "dscrgrp", "placeholder", "placeholder", "placeholder", "placeholder", "ctzshipc", "brncntr", "placeholder", "livecnta", "hhmmb", "gndr", "yrbrn", "agea",  "chldhm", "eduyrs", "pdwrk", "imptrad", "placeholder", "inwyye", "placeholder", "hinctnta", "placeholder", "lnghom1", "facntr", "mocntr", "placeholder","placeholder", "fbrncntb", "placeholder", "placeholder", "mbrncntb",  "placeholder", "rshipa2", "placeholder", "rshipa3", "icpart1", "region", "regunit", "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder", "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder",  "placeholder", "inwdds", "inwdde", "placeholder", "inwmms", "inwmme","impfree", "pplfair", "pbldmn", "badge", "placeholder","inwyys", "inwyye", 
#which party close to
"prtclcat", "placeholder", "placeholder",
"prtclcbe","placeholder", "placeholder", "placeholder",
"placeholder", "placeholder", "placeholder", "placeholder",
"prtclfch","placeholder", "placeholder", "placeholder","placeholder","placeholder",
"placeholder","placeholder",
"prtcldcz","placeholder","placeholder","placeholder","placeholder",
"prtclede" ,"placeholder","placeholder","placeholder","placeholder","placeholder",
"placeholder","placeholder","placeholder","placeholder",

"prtclfee", "placeholder","placeholder","placeholder","placeholder","placeholder",
"prtclees", "placeholder","placeholder","placeholder","placeholder",
"prtcldfi", "placeholder","placeholder","placeholder",
"prtclefr","placeholder","placeholder","placeholder","placeholder",
"prtclbgb","placeholder","placeholder",
"placeholder","placeholder","placeholder","placeholder",
"placeholder",
"prtclfhu","placeholder","placeholder","placeholder","placeholder","placeholder",
"prtclcie","placeholder","placeholder", 
"prtcldil", "placeholder","placeholder","placeholder","placeholder", 
"prtclbis", "placeholder",
"prtclcit","placeholder","placeholder",
"placeholder",
"prtclblt","placeholder",
"prtclenl","placeholder","placeholder","placeholder","placeholder","placeholder",
"prtclbno" ,"placeholder","placeholder",
"prtclgpl","placeholder","placeholder","placeholder","placeholder","placeholder","placeholder",
 "prtclept","placeholder","placeholder","placeholder","placeholder",
"prtcldru","placeholder","placeholder","placeholder",
"prtclbse", "placeholder","placeholder",
 "prtclesi", "placeholder","placeholder","placeholder","placeholder","placeholder",
"placeholder","placeholder","placeholder","placeholder",
"placeholder","placeholder",
"placeholder","placeholder","placeholder","placeholder","placeholder", "placeholder", "nwspol", "rlgdnm")]


colnames(data8)<-c("idno","cntry", "essround", "dweight", "pspwght", "pweight", "tvtot", "tvpol", "nwsppol", "netuse", "ppltrst", "polintr", "trstprl", "trstlgl", "trstplc", "trstplt", "trstprt", "trstep", "trstun", "vote", "contplt", "wrkprty", "sgnptit", "clsprty", "lrscale", "stflife", "stfeco", "stfgov","stfdem", "stfedu", "happy", "sclmeet", "sclact", "crmvct", "health", "rlgblg", "rlgdnm", "rlgdgr", "rlgatnd", "dscrgrp", "ctzcntr", "ctzship", "ctzshipa", "ctzshipb", "ctzshipc", "brncntr", "livecntr", "livecnta", "hhmmb", "gndr", "yrbrn", "agea", "chldhm", "eduyrs", "pdwrk", "imptrad", "inwyr", "inwyye", "hinctnt", "hinctnta", "lnghoma", "lnghom1", "facntr", "mocntr", "fbrncnt","fbrncnta", "fbrncntb", "mbrncnt", "mbrncnta", "mbrncntb", "rship2", "rshipa2", "rship3", "rshipa3", "partner" , "cregion",  "regunit",  "regionat", "regionbe", "regionbg" ,"regionch", "regioach" ,"regioncy" ,"regioncz", "regioacz", "regionde", "regiondk", "regioadk" ,"regionee", "regiones", "regioaes" , "regionfi" , "regioafi", "regionfr", "regiongb", "regiongr", "regioagr", "regionhr" ,"regionhu", "regionie", "regioaie", "regiobie", "regionil", "regionit", "regionlu", "regionnl", "regionno" , "regionpl", "regionpt" , "regioapt", "regionru", "regionse", "regionsi", "regionsk", "regiontr" ,"regionua", "inwdd", "inwdds", "inwdde", "inwmm", "inwmms", "inwmme", "impfree", "pplfair",  "pbldmn", "badge" ,"inwyr", "inwyys", "inwyye",
#which party close to?
"prtclat",  "prtclaat",  "prtclcat",
"prtclbe",  "prtclabe", "prtclbbe", "prtclcbe",
"prtclbg" , "prtclabg", "prtclbbg", "prtclcbg",
"prtclch",  "prtclach", "prtclbch", "prtclcch", "prtcldch", "prtclech",
"prtclcy",  "prtclacy",
"prtclcz",  "prtclacz", "prtclbcz", "prtclccz", "prtcldcz",
"prtclde" , "prtclade", "prtclbde", "prtclcde", "prtcldde", "prtclede",
"prtcldk",  "prtcladk", "prtclbdk", "prtclcdk",
"prtclee",  "prtclaee", "prtclbee", "prtclcee", "prtcldee", "prtcleee",
"prtcles",  "prtclaes", "prtclbes","prtclces", "prtcldes",
"prtclfi",  "prtclafi", "prtclbfi", "prtclcfi", 
"prtclfr",  "prtclafr", "prtclbfr", "prtclcfr", "prtcldfr",
"prtclgb",  "prtclagb", "prtclbgb",
"prtclgr",  "prtclagr" ,"prtclbgr", "prtclcgr",
"prtclhr",
"prtclhu",  "prtclahu", "prtclbhu", "prtclchu", "prtcldhu", "prtclehu",
"prtclie",  "prtclaie","prtclbie",
"prtclil",  "prtclail", "prtclbil", "prtclcil", "prtcldil",
"prtclis",  "prtclais", 
"prtclit", "prtclait", "prtclbit",
"prtcllu",
"prtcllt",  "prtclalt",
"prtclnl",  "prtclanl", "prtclbnl", "prtclcnl", "prtcldnl", "prtclenl",
"prtclno",  "prtclano", "prtclbno",
"prtclpl",  "prtclapl", "prtclbpl", "prtclcpl","prtcldpl", "prtclepl", "prtclfpl", 
"prtclpt", "prtclapt", "prtclbpt", "prtclcpt", "prtcldpt",
"prtclru", "prtclaru", "prtclbru", "prtclcru",
"prtclse",  "prtclase", "prtclbse",
"prtclsi",  "prtclasi", "prtclbsi", "prtclcsi", "prtcldsi", "prtclesi",
 "prtclsk",  "prtclask", "prtclbsk", "prtclcsk",
"prtcltr",  "prtclatr",
"prtclua" , "prtclaua", "prtclbua", "prtclcua", "prtcldua", "rdpol", "nwsppol", "rlgdnm"
)

data1<-rbind(data1_7, data8, make.row.names = F)

###################################################
#####          VARIABLES         #################
##################################################
#Number of waves
unique(data1$essround)



#Islam

data1$Islam<-ifelse(data1$rlgdnm=="Islamic", 1, 0)
summary(data1$Islam)

#Close to a party?
unique(data1$clsprty)
head(data1$clsprty)
data1$clsprty_num1<-as.numeric(data1$clsprty)
unique(data1$clsprty_num1)
head(data1$clsprty_num1)
data1$clsprty_num<-ifelse(data1$clsprty_num1==2, 0, data1$clsprty_num1)
data1$clsprty_num<-ifelse(data1$clsprty_num1>2, NA, data1$clsprty_num)

head(data1$clsprty_num)



#IMPORTANT VARIABLE: what outside the host country citizenship do you hold? Question asked only to those who answered "NO" or "I DON"T KNOW" to the question C18 or C26 : Are you citizen of the "Host" country? --> this means that we are missing the double citizens
 #SEE "ROUTING" in the ESS codebook
 
data1$citizenship<-rep(NA, nrow(data1))
data1$citizenship[which(data1$essround==1)]<-data1$ctzship[which(data1$essround==1)]
data1$citizenship[which(data1$essround==2 | data1$essround==3)]<-data1$ctzshipa[which(data1$essround==2 | data1$essround==3)]
data1$citizenship[which(data1$essround==4 | data1$essround==5)]<-data1$ctzshipb[which(data1$essround==4 | data1$essround==5)]
data1$citizenship[which(data1$essround==6 | data1$essround==7 | data1$essround==8)]<-data1$ctzshipc[which(data1$essround==6 | data1$essround==7 | data1$essround==8)]

unique(data1$citizenship)

table(data1$citizenship, data1$ctzcntr)


#Subsetting only to non-citizens:

data<-data1[which(data1$citizenship!="66" & data1$citizenship!="99" & data1$citizenship!="65"  & data1$citizenship!="77"   & data1$citizenship!="88"   & data1$citizenship!="02" & data1$citizenship!="03" & data1$citizenship!="04" &  data1$citizenship!="06" ),]

#Dropping the I don't know/no response and countries that do no exist anymore like USSR, DDR, Czechoslovakia and Yugoslavia
#NOTE#65 is the Alien's document --> some country give this travelling ID to individuals who are stateless or incapable of getting a passport from the homecountry

setwd("/Users/chiarasuperti/Dropbox/Immigrants Abroad/ESS Vote Abroad Paper/Writing Material Voting Abroad ESS")


#BORN IN THE HOST COUNTRY
data$native<-ifelse(data$brncntr=="Yes", 1, 0)

#Gender
unique(data$gndr)
data$gndr_num<-c()
data$gndr_num[data$gndr=="Female"]<-1
data$gndr_num[data$gndr=="Male"]<-0
data$gndr_num[data$gndr=="No answer"]<-NA


#CITIZEN HOST COUNTRY

data$citizen_host1<-as.numeric(data$ctzcntr)
data$citizen_host<-ifelse(data$citizen_host1==2, 0, data$citizen_host1 )

summary(data$citizen_host)

#Summary of Citizenship and place of birth: interesting since birth and citizenship do correspond in many of these countries
table(data$native, data$ctzcntr)
sum(data$citizen_host==0, na.rm=T)#11794, the rest in non-responses: 1723
sum(data$citizen_host==1, na.rm=T)#7 --> there should be none
table(data$citizenship, data$native)


##Creating year of the survey:

data$year_survey<-rep(NA, nrow(data))
data$year_survey[which(data$essround%in%c(1,2))]<-data$inwyr[which(data$essround%in%c(1,2))]
data$year_survey[which(data$essround%in%c(3, 4, 5, 6, 7, 8))]<-data$inwyye[which(data$essround%in%c(3, 4, 5, 6, 7, 8))]
data$year_survey[which(data$year_survey=="9999")]<-NA

sort(unique(data$year_survey))
table(data$year_survey)


#Survey wave

data$essround_num<-as.numeric(data$essround)


#VARIABLE TIME SPENT
#Important: this was asked only to people who were borned abroad (so not all people with a different citizenship were born abroad see before!)
#livecntr --> till 4 with generic time frame
#livecnta---> 5 to 8 with precise number of years

data$livecnta[which(data$essround==8)]<-ifelse(data$livecnta[which(data$essround==8)]>2016, NA, data$livecnta[which(data$essround==8)])

data$years_from_migr<-rep(NA, nrow(data))
data$years_from_migr<-data$year_survey-data$livecnta
 
data$time_from_migr<-rep(NA, nrow(data))
data$time_from_migr[which(data$essround_num<5)]<-as.numeric(data$livecntr[which(data$essround_num<5)])
data$time_from_migr[which(data$essround_num<5 & as.numeric(data$livecntr)>5)]<-NA
data$time_from_migr[which(data$essround_num>4 & data$years_from_migr<1)]<-1
data$time_from_migr[which(data$essround_num>4 & data$years_from_migr<6 & data$years_from_migr>0)]<-2
data$time_from_migr[which(data$essround_num>4 & data$years_from_migr<11 & data$years_from_migr>5)]<-3
data$time_from_migr[which(data$essround_num>4 & data$years_from_migr<21 & data$years_from_migr>10)]<-4
data$time_from_migr[which(data$essround_num>4 & data$years_from_migr>20)]<-5

##For natives let's use the age
data$time_from_migr[which( data$native==1 & data$agea>10 & data$agea<21)]<-4
data$time_from_migr[which( data$native==1 & data$agea>20)]<-5

table(data$time_from_migr, data$essround_num)
  
#some summaries of the time spent in the country
summary(data$time_from_migr)
summary(data$years_from_migr)        

table(data$time_from_migr, data$years_from_migr)
table(data$time_from_migr)

####Other summaries
length(unique(data$cntry))#32
length(unique(data$citizenship))#176


############################################################################################################
##MAIN EXPLANATORY VARIABLE: Accessibility of Vote from Abroad (ease of enfranchisment/actual enfranchisment)
############################################################################################################
data$VA_easy<-rep(NA, nrow(data))
data$first_year<-rep(NA, nrow(data))

#CODING SCHEME
#VA_easy: from impossible to very easy:
#0=no direct actual election, 1 =no external voting, 2=yes, but very difficult (i.e. border ) or only on papers or only for small groups like military, 3=easy but in persion at embassy only or proxy 4=postal , 5= evote
######################################################################################################################################
#Things Thought about and/or added: 
#1. countries with term limit: 
# Germany (25 years for persons resident in countries that are not members of the Council of Europe), New Zealand (three years for citizens, 12 months for permanent residents) and the UK (15 years) --> DONE
#2.Important source Idea.int (Institute for Democracy and Electoral Assistance. 2018. Voting from Abroad Database. https:/ www.idea.int/data-tools/data/voting-abroad.) but multiple additional sources used (see link or reference for each case)
#3. For diplomatic missions: embassypage main source with other cross-checking or different sources when available --> limitation: only 2018 
##############################################################################################################################################################################

#United Emirates
data$first_year[data$citizenship=="AE"]<-NA
data$VA_easy[data$citizenship=="AE"]<-0

#Afghanistan--> partially applied as "personal 2002-2007 but only on paper after --> classified as 2 also only for people in IRan and Pakistan
data$first_year[data$citizenship=="AF"]<-2002
data$VA_easy[data$citizenship=="AF" & data$year_survey<2002]<-1
data$VA_easy[data$citizenship=="AF" & data$year_survey>2001]<-2

#Albania
#transition in 1996
data$first_year[data$citizenship=="AL"]<-NA
data$VA_easy[data$citizenship=="AL"]<-1

#Armenia
#https://www.rferl.org/a/armenia-expatriates-voting/24903351.html
#https://www.refworld.org/docid/46f2584123.html
data$first_year[data$citizenship=="AM"]<-2007
data$VA_easy[data$citizenship=="AM" & data$year_survey<2007]<-1
data$VA_easy[data$citizenship=="AM" & data$year_survey>2006]<-2


#Netherland Antilles (dissolved in 2010)
data$first_year[data$citizenship=="AN"]<-NA
data$VA_easy[data$citizenship=="AN" & data$year_survey<2010  ]<-1
data$VA_easy[data$citizenship=="AN" & data$year_survey>2009 ]<-NA

#Angola
#Hartmann 2015
#http://www.angop.ao/angola/en_us/noticias/politica/2017/0/1/Electoral-Commission-plenary-session-decide-voting-abroad,75db9ab0-f971-4e63-a924-de098fef4790.html
#http://www.angop.ao/angola/en_us/noticias/politica/2017/4/20/Angola-CNE-studies-regulation-for-early-voting-offshore,61b88351-38de-4a78-a468-735c1e882299.html
#Law not implemented yet --> debate still ongoing 
#https://www.eisa.org.za/wep/angola.htm # NO DIRECT ELECTIONS BEFORE 1992
data$first_year[data$citizenship=="AO"]<-1992
data$VA_easy[data$citizenship=="AO" & data$year_survey<1992]<-0
data$VA_easy[data$citizenship=="AO" & data$year_survey>1991]<-2


#Argentina: in person at the embassies classified as 3
#Year of implementation according to LA report says 1993 and legislation seems to confirm that too.
#https://www.argentina.gob.ar/argentinosenelmundo/vota-desde-el-exterior 
#Not mandatory for people living abroad
data$first_year[data$citizenship=="AR"]<-1993
data$VA_easy[data$citizenship=="AR" & data$year_survey<1993]<-1
data$VA_easy[data$citizenship=="AR" & data$year_survey>1992]<-3


#American Samoa
data$first_year[data$citizenship=="AS"]<-NA
data$VA_easy[data$citizenship=="AS"]<-1


#Austria
#https://www.austria.org/elections
data$first_year[data$citizenship=="AT"]<-1990
data$VA_easy[data$citizenship=="AT" & data$year_survey>1989]<-4
data$VA_easy[data$citizenship=="AT" & data$year_survey<1990]<-1


#Australia
data$first_year[data$citizenship=="AU"]<-1949
data$VA_easy[data$citizenship=="AU" & data$year_survey>1948]<-4
data$VA_easy[data$citizenship=="AU" & data$year_survey<1949]<-1


#Aruba
data$first_year[data$citizenship=="AW"]<-NA
data$VA_easy[data$citizenship=="AW"]<-1


#Azerbaijan
data$first_year[data$citizenship=="AZ"]<-2000
data$VA_easy[data$citizenship=="AZ" & data$year_survey<2000]<-1
data$VA_easy[data$citizenship=="AZ" & data$year_survey>1999]<-3
No_Country_AZ<-c("IL", "SI", "GR", "LU", "CY", "SK", "IE","IS", "DK", "FI", "NO", "PT") #from gov website and doc downloaded (some of these countries are under other countries, other don't have embassies at all)
data$VA_easy[data$citizenship=="AZ" & data$year_survey>1999 & data$cntry%in%No_Country_AZ]<-2


#Bosnia Herzegovina
#file:///Users/chiarasuperti/Downloads/Bosnia_Herzegovina_election_law_2001_am2016_en.pdf
#temporarily abroad and refugees from BiH
data$first_year[data$citizenship=="BA"]<-1996
data$VA_easy[data$citizenship=="BA"  & data$year_survey<1996]<-1
data$VA_easy[data$citizenship=="BA"  & data$year_survey>1995]<-4


#Bangladesh: it says "postal officially" but actually only diplomatic staff and government seem to be able to do it so I gave it a 2
data$first_year[data$citizenship=="BD"]<-1972
data$VA_easy[data$citizenship=="BD"  & data$year_survey<1972]<-1
data$VA_easy[data$citizenship=="BD"  & data$year_survey>1971]<-2


#Belgium
data$first_year[data$citizenship=="BE"]<-1998
data$VA_easy[data$citizenship=="BE" & data$year_survey<1998]<-1
data$VA_easy[data$citizenship=="BE" & data$year_survey>1997]<-4

#Burkina Faso
#Hartman says "yes" , differnet from Idea Int --> difficult to code: I think from information below the truth is in the middle --> law not implemented
#https://au.int/en/newsevents/19421/burkina-faso-presidential-and-legislative-elections-29-november-2015
#https://freedomhouse.org/report/freedom-world/2016/burkina-faso
#http://mobile.apanews.net/index.php/en/news/burkina-faso-president-kabore-to-run-for-second-term
data$first_year[data$citizenship=="BF"]<-2009
data$VA_easy[data$citizenship=="BF"  & data$year_survey<2009]<-1
data$VA_easy[data$citizenship=="BF"  & data$year_survey>2008]<-2


#Bulgaria
#https://www.eurochicago.com/2010/10/elections-in-bulgaria/
#https://www.novinite.com/articles/177378/Bulgarians+Abroad+Voting+in+71+States
#https://www.novinite.com/articles/177252/Queues%2C+Ballot+Shortage+Reported+in+Some+Bulgarian+Polling+Stations+Abroad
#https://www.novinite.com/articles/177267/More+Than+106+000+Bulgarians+Abroad+Voted+for+President
#http://blogs.lse.ac.uk/europpblog/2016/05/03/limiting-the-vote-from-abroad-erodes-bulgarias-democracy-evidence-from-the-electoral-integrity-project/
#https://www.novinite.com/articles/174159/Bulgarian+Voters+Abroad+to+Cast+Ballots+in+Diplomatic+Missions+Only
#Important change in 2016 --> only consulate can be used, so decrease in locations to cast vote, however still multiple polls per country as long as there are at least 20 voters registered --> low bar
data$first_year[data$citizenship=="BG"]<-1990
data$VA_easy[data$citizenship=="BG" & data$year_survey<1990]<-1
data$VA_easy[data$citizenship=="BG" & data$year_survey>1989]<-3
No_Country_BG<-c("EE", "IS", "LT")
data$VA_easy[data$citizenship=="BG" & data$year_survey>1989 & data$cntry%in%No_Country_BG]<-2



#Bahrain
data$first_year[data$citizenship=="BH"]<-2010
data$VA_easy[data$citizenship=="BH" & data$year_survey>2009]<-4
data$VA_easy[data$citizenship=="BH" & data$year_survey<2010]<-1


#Burundi
data$first_year[data$citizenship=="BI"]<-2010
data$VA_easy[data$citizenship=="BI" & data$year_survey>2009]<-3
data$VA_easy[data$citizenship=="BI" & data$year_survey<2010]<-1
#https://www.embassypages.com/burundi
No_Country_BI<-c("BG", "CZ", "EE", "ES", "GR", "HR", "HU", "IE", "IS", "LT", "NO", "PL", "PT", "SE", "UA")
data$VA_easy[data$citizenship=="BI" & data$year_survey>2009 & data$cntry%in%No_Country_BI]<-2

#Benin
data$first_year[data$citizenship=="BJ"]<-2010
data$VA_easy[data$citizenship=="BJ" & data$year_survey<2010]<-1
data$VA_easy[data$citizenship=="BJ" & data$year_survey>2009]<-3
No_Country_BJ<-c("EE", "LT", "LU", "SI") #http://www.mofat.gov.bn/Pages/Foreign-Diplomatic-Missions.aspx
data$VA_easy[data$citizenship=="BJ" & data$year_survey>2009 & data$cntry%in%No_Country_BJ]<-2


#Brunei
data$first_year[data$citizenship=="BN"]<-NA
data$VA_easy[data$citizenship=="BN"]<-0


#Bolivia Personal from 2009
#But only for Argentina, Spain Brazil, US: source Lafleur, 2016
data$first_year[data$citizenship=="BO"]<-1991
data$VA_easy[data$citizenship=="BO" & data$year_survey<1991]<-1
data$VA_easy[data$citizenship=="BO" & data$year_survey>1990 & data$year_survey<2009]<-2
data$VA_easy[data$citizenship=="BO" & data$year_survey>2008 & data$cntry=="ES"]<-3
data$VA_easy[data$citizenship=="BO" & data$year_survey>2008 & data$cntry!="ES"]<-2


#Brazil
data$first_year[data$citizenship=="BR"]<-1989
data$VA_easy[data$citizenship=="BR" & data$year_survey<1989]<-0
data$VA_easy[data$citizenship=="BR" & data$year_survey>1988]<-3
#http://english.tse.jus.br/noticias-tse-en/2014/Julho/an-increased-number-of-brazilian-voters-are-eligible-to-vote-abroad
#From above: minimum 30 people, vote in embassies, consulate or other locations
No_Country_BR<-c("IS", "LT", "LU") 
data$VA_easy[data$citizenship=="BR" & data$year_survey>1988 & data$cntry%in%No_Country_BR]<-2

#Botswana  
# see also: https://aceproject.org/ace-en/topics/va/annex/country-case-studies/botswana-disappointing-results-of-external-voting
data$first_year[data$citizenship=="BW"]<-1999
data$VA_easy[data$citizenship=="BW" & data$year_survey<1999]<-1
data$VA_easy[data$citizenship=="BW" & data$year_survey>1998]<-2
Yes_Country_BW<-c("BE", "DE", "GB", "SE") #list from wikipedia
data$VA_easy[data$citizenship=="BW" & data$year_survey>1998 & data$cntry%in%Yes_Country_BW]<-3


#Belarus 
data$first_year[data$citizenship=="BY"]<-2004
data$VA_easy[data$citizenship=="BY" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="BY" & data$year_survey>2003]<-3
No_Country_BY<-c("LU", "NO",  "IS", "PT", "DK")
data$VA_easy[data$citizenship=="BY" & data$year_survey>2003 & data$cntry%in%No_Country_BY]<-2


#Canada
data$first_year[data$citizenship=="CA"]<-1945
data$VA_easy[data$citizenship=="CA" & data$year_survey<1945]<-1
data$VA_easy[data$citizenship=="CA" & data$year_survey>1944]<-4

#Congo (Dem Rep of)
data$first_year[data$citizenship=="CD"]<-2018
data$VA_easy[data$citizenship=="CD" & data$year_survey<2018]<-1
data$VA_easy[data$citizenship=="CD" & data$year_survey>2017]<-3
No_Country_CD<-c("BG", "CY", "EE", "FI", "HR", "HU", "IE", "IS", "LT", "LU", "NE", "NO", "SI", "UA")
data$VA_easy[data$citizenship=="CD" & data$year_survey>2017 & data$cntry%in%No_Country_CD]<-2


#Central Africa Rep--> on the paper since 2009, no data on actual use (2009 year of the reform)
data$first_year[data$citizenship=="CF"]<-2009
data$VA_easy[data$citizenship=="CF" & data$year_survey<2009]<-1
data$VA_easy[data$citizenship=="CF" & data$year_survey>2008]<-2


#Congo (Brazzaville) only registration not voting discussed in the law
data$first_year[data$citizenship=="CG"]<-2001
data$VA_easy[data$citizenship=="CG" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="CG" & data$year_survey>2000]<-2

#Switzerland: e-voting
data$first_year[data$citizenship=="CH"]<-2011
data$VA_easy[data$citizenship=="CH" & data$year_survey<2011]<-4
data$VA_easy[data$citizenship=="CH" & data$year_survey>2010]<-5

#Cote d'ivoire --> unclear why idea.int put 1995 as first year but then says it's after 2000
data$first_year[data$citizenship=="CI"]<-2000
data$VA_easy[data$citizenship=="CI" & data$year_survey<2000]<-1
data$VA_easy[data$citizenship=="CI" & data$year_survey>1999]<-3

No_Country_CI<-c("BG","CZ", "EE", "IE", "IS", "LT", "PL", "SI")
data$VA_easy[data$citizenship=="CI" & data$year_survey>1999 & data$cntry%in%No_Country_CI]<-2

#Chile
#https://www.servel.cl/voto-de-chilenos-en-el-exterior-2/
#https://www.servel.cl/wp-content/uploads/2017/04/Tabla_Circunscripciones.pdf
data$first_year[data$citizenship=="CL"]<-2017
data$VA_easy[data$citizenship=="CL" & data$year_survey<2017]<-1
data$VA_easy[data$citizenship=="CL" & data$year_survey>2016]<-3


#Cameroon
data$first_year[data$citizenship=="CM"]<-2011
data$VA_easy[data$citizenship=="CM" & data$year_survey<2011]<-1
data$VA_easy[data$citizenship=="CM" & data$year_survey>2010]<-3

No_Country_CM<-c("BG", "CZ", "EE", "FI", "HR", "HU", "IS", "LT", "LU", "NO", "PL", "SI", "SL")
data$VA_easy[data$citizenship=="CM" & data$year_survey>2010 & data$cntry%in%No_Country_CM]<-2

#China
data$first_year[data$citizenship=="CN"]<-NA
data$VA_easy[data$citizenship=="CN" & data$year_survey<2017]<-0
data$VA_easy[data$citizenship=="CN" & data$year_survey>2016]<-0

#Colombia
data$first_year[data$citizenship=="CO"]<-1961
data$VA_easy[data$citizenship=="CO" & data$year_survey<1961]<-1
data$VA_easy[data$citizenship=="CO" & data$year_survey>1960]<-3
No_Country_CO<-c("EE", "HR", "IS", "SI")
data$VA_easy[data$citizenship=="CO" & data$year_survey>1960 & data$cntry%in%No_Country_CO]<-2


#Serbia and Montenegro: country did not exist for long -> what citizenship people got afterward?
#https://www.osce.org/odihr/elections/serbia/235936?download=true
#http://blogs.lse.ac.uk/europpblog/2017/04/01/serbian-presidential-elections-the-diaspora-vote/
data$first_year[data$citizenship=="CS"]<-NA
data$VA_easy[data$citizenship=="CS" & data$year_survey<2017]<-1
data$VA_easy[data$citizenship=="CS" & data$year_survey>2016]<-1

#Cuba
data$first_year[data$citizenship=="CU"]<-NA
data$VA_easy[data$citizenship=="CU" & data$year_survey<1961]<-1
data$VA_easy[data$citizenship=="CU" & data$year_survey>1960]<-1

#Cape verde
#http://aceproject.org/ace-en/topics/va/comparative-review/comparative-review-of-voting-from-abroad
#one party system from 1970 to 1990
data$first_year[data$citizenship=="CV"]<-1991
data$VA_easy[data$citizenship=="CV" & data$year_survey<1991]<-0
data$VA_easy[data$citizenship=="CV" & data$year_survey>1990]<-2
Yes_Country_CV<-c(  "BE", "FR", "DE", "IT", "LU", "PT", "ES", "CZ", "FI", "AT", "CY", "IL", "NL", "RU", "CH", "GB", "SE")
data$VA_easy[data$citizenship=="CV" & data$year_survey>1990 & data$cntry%in%Yes_Country_CV]<-3


#Cyprus
#Minimum period of habitual residence of six months: http://www.europarl.europa.eu/RegData/etudes/IDAN/2015/564379/EPRS_IDA(2015)564379_EN.pdf
data$first_year[data$citizenship=="CY"]<-2011
data$VA_easy[data$citizenship=="CY" & data$year_survey<2011]<-1
data$VA_easy[data$citizenship=="CY" & data$year_survey>2010]<-3
No_Country_CY<-c("BE", "LT", "TR")
data$VA_easy[data$citizenship=="CY" & data$year_survey>2010 & data$cntry%in%No_Country_CM]<-2


#Czech Republic
data$first_year[data$citizenship=="CZ"]<-2002
data$VA_easy[data$citizenship=="CZ" & data$year_survey<2002]<-1
data$VA_easy[data$citizenship=="CZ" & data$year_survey>2001]<-3


#German
data$first_year[data$citizenship=="DE"]<-1985
data$VA_easy[data$citizenship=="DE" & data$year_survey<1985]<-1
data$VA_easy[data$citizenship=="DE" & data$year_survey>1984]<-4

#Denmark
#Permanently domiciled in the realm, unless the citizen resident abroad intends to return to Denmark within two years: http://www.europarl.europa.eu/RegData/etudes/IDAN/2015/564379/EPRS_IDA(2015)564379_EN.pdf
data$first_year[data$citizenship=="DK"]<-1980
data$VA_easy[data$citizenship=="DK" & data$year_survey<1980]<-1
data$VA_easy[data$citizenship=="DK" & data$year_survey>1979]<-4


#Dominica
#http://dominicanewsonline.com/news/homepage/news/politics/analyst-takes-a-dim-view-of-nationals-brought-in-to-vote/
#they have to return and lots of money is spent to make them come back (at least from neighboring places)
#http://www.caribbeanelections.com/dm/education/default.asp
##Time limit: 5 years "absent" and can vote; missing beginning year: Frm the 1974 law 5 years requirements, otherwise still a voter in the district

data$first_year[data$citizenship=="DM"]<-1974
data$VA_easy[data$citizenship=="DM"  & data$year_survey>1974]<-1
data$VA_easy[data$citizenship=="DM"  & data$year_survey>1974]<-2
data$VA_easy[data$time_from_migration>2 & data$citizenship=="DM"]<-1 #2 is the category 1-5 years


#Dominican Rep
#http://jce.gob.do/Cedulacion-Exterior
data$first_year[data$citizenship=="DO"]<-2004
data$VA_easy[data$citizenship=="DO" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="DO" & data$year_survey>2003]<-2
Yes_Country_DO<-c("NL", "IT", "ES", "CH")
data$VA_easy[data$citizenship=="DO" & data$year_survey>2003 & data$cntry%in%Yes_Country_DO]<-3


#Algeria
#https://journals.sagepub.com/doi/full/10.1177/2347798917744298 
data$first_year[data$citizenship=="DZ"]<-1976
data$VA_easy[data$citizenship=="DZ" & data$year_survey<1976]<-1
data$VA_easy[data$citizenship=="DZ" & data$year_survey>1975]<-3
No_Country_DZ<-c("CY", "EE", "IE", "IL", "IS", "LT", "LU", "SI", "SK")
data$VA_easy[data$citizenship=="DZ" & data$year_survey>1975 & data$cntry%in%No_Country_DZ]<-2


#Ecuador
#http://votoenelexterior.cne.gob.ec/preguntas-frecuentas
#https://resultados2018.cne.gob.ec/
#http://cne.gob.ec/documents/lotaip/2.informacion_legal/base_legal/ley_orgnica_electoral_-_cdigo_de_la_democracia.pdf
data$first_year[data$citizenship=="EC"]<-2006
data$VA_easy[data$citizenship=="EC" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="EC" & data$year_survey>2005]<-2
Yes_Country_EC<-c("BE", "ES", "PT", "SE", "DE", "IT", "FR", "GB", "TR", "NL", "CH", "AT", "HU")
data$VA_easy[data$citizenship=="EC" & data$year_survey>2005 & data$cntry%in%Yes_Country_EC]<-3



#Estonia
data$first_year[data$citizenship=="EE"]<-1992
data$VA_easy[data$citizenship=="EE" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="EE" & data$year_survey>1991 & data$year_survey<2006]<-4
data$VA_easy[data$citizenship=="EE" & data$year_survey>2005 & data$year_survey<2012]<-5
data$VA_easy[data$citizenship=="EE" & data$year_survey>2011]<-4

#Egypt
#https://www.ifes.org/sites/default/files/2018_ifes_egypt_presidential_elections_faqs_final.pdf
#https://www.cnn.com/2012/05/11/world/africa/egypt-voting-abroad/index.html
data$first_year[data$citizenship=="EG"]<-2012
data$VA_easy[data$citizenship=="EG" & data$year_survey<2012]<-1
data$VA_easy[data$citizenship=="EG" & data$year_survey>2011]<-3
No_Country_EG<-c("IS", "LU", "LT")
data$VA_easy[data$citizenship=="EG" & data$year_survey>2011 & data$cntry%in%No_Country_EG]<-2

#Eritrea
data$first_year[data$citizenship=="ER"]<-NA
data$VA_easy[data$citizenship=="ER" & data$year_survey<2006]<-0
data$VA_easy[data$citizenship=="ER" & data$year_survey>2005]<-0

#Spain
data$first_year[data$citizenship=="ES"]<-1985
data$VA_easy[data$citizenship=="ES" & data$year_survey<1985]<-1
data$VA_easy[data$citizenship=="ES" & data$year_survey>1984]<-4

#Ethiopia
data$first_year[data$citizenship=="ET"]<-NA
data$VA_easy[data$citizenship=="ET" & data$year_survey<1991]<-0
data$VA_easy[data$citizenship=="ET" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="ET" & data$year_survey>2005]<-1

#Finland
data$first_year[data$citizenship=="FI"]<-1958
data$VA_easy[data$citizenship=="FI" & data$year_survey<1958]<-1
data$VA_easy[data$citizenship=="FI" & data$year_survey>1957]<-3
No_Country_FI<-c("LU")
data$VA_easy[data$citizenship=="FI" & data$year_survey>1957 & data$cntry%in%No_Country_FI]<-2


#France
#https://www.reuters.com/article/uk-france-election-cyber/france-drops-electronic-voting-for-citizens-abroad-over-cybersecurity-fears-idUKKBN16D235
#http://time.com/4752023/france-presidential-election-voters-hong-kong/

data$first_year[data$citizenship=="FR"]<-1926
data$VA_easy[data$citizenship=="FR" & data$year_survey<2012 & data$year_survey>1974 ]<-3
data$VA_easy[data$citizenship=="FR" & data$year_survey>1926 & data$year_survey<1975]<-4
data$VA_easy[data$citizenship=="FR" & data$year_survey>2011 & data$year_survey<2017]<-5
data$VA_easy[data$citizenship=="FR" & data$year_survey>2016]<-3

#Gabon 
#Source Hartman 2015 says yes, but I couldn't find any evidence of law being implemented and Idea.int says not implemented--> final result is a combination of the two sources 
data$first_year[data$citizenship=="GA"]<-1998
data$VA_easy[data$citizenship=="GA" & data$year_survey<1998]<-1
data$VA_easy[data$citizenship=="GA" & data$year_survey>1998  & data$year_survey<2006]<-2
data$VA_easy[data$citizenship=="GA" & data$year_survey>2005]<-2
Yes_Country_GA<-c("BE", "FR","DE", "IT", "ES", "TR", "GB", "CY", "FI", "LU", "NL", "SE")
data$VA_easy[data$citizenship=="GA" & data$year_survey>2005 & data$cntry%in%Yes_Country_GA]<-3

#UK
#2016 interesting proposal change of time --> dropping the 15 years limit for UK people living abroad
#https://www.gov.uk/government/news/government-delivers-on-pledge-to-give-back-british-expats-the-right-to-vote
#https://www.gov.uk/government/publications/a-democracy-that-works-for-everyone-british-citizens-overseas
data$first_year[data$citizenship=="GB"]<-1985
data$VA_easy[data$citizenship=="GB" & data$year_survey<1985]<-1
data$VA_easy[data$citizenship=="GB" & data$year_survey>1984]<-4

#Grenada
data$first_year[data$citizenship=="GD"]<-NA
data$VA_easy[data$citizenship=="GD" & data$year_survey<1958]<-1
data$VA_easy[data$citizenship=="GD" & data$year_survey>1957]<-1

#Georgia
data$first_year[data$citizenship=="GE"]<-1995
data$VA_easy[data$citizenship=="GE" & data$year_survey<1995]<-1
data$VA_easy[data$citizenship=="GE" & data$year_survey>1994]<-3
No_Country_GE<-c("HR", "LU")
data$VA_easy[data$citizenship=="GE" & data$year_survey>1994 & data$cntry%in%No_Country_GE]<-2



#Ghana: also only for some specific individuals, not everyone
data$first_year[data$citizenship=="GH"]<-2006
data$VA_easy[data$citizenship=="GH" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="GH" & data$year_survey>2005]<-2

#Greenland --> couldn't find any additional information
#http://www.electionguide.org/countries/id/86/
data$first_year[data$citizenship=="GL"]<-NA
data$VA_easy[data$citizenship=="GL" & data$year_survey<2011]<-1
data$VA_easy[data$citizenship=="GL" & data$year_survey>1957]<-1

#Gambia
#http://www.eods.eu/library/final_report_eu_eom_the_gambia_2017_0.pdf
#Hartmann actually would put in a 2
data$first_year[data$citizenship=="GM"]<-NA
data$VA_easy[data$citizenship=="GM" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="GM" & data$year_survey>2005]<-1

#Guinea
#https://www.cartercenter.org/resources/pdfs/news/peace_publications/election_reports/guinea-2010-finalreport.pdf
#18 embassies in 2010
data$first_year[data$citizenship=="GN"]<-1993
data$VA_easy[data$citizenship=="GN" & data$year_survey<1993]<-1
data$VA_easy[data$citizenship=="GN" & data$year_survey>1992]<-2
Yes_Country_GN<-c("AT", "BE", "FR", "IT", "RU", "ES", "TR", "BG", "DE", "LU", "PT",  "CH")
data$VA_easy[data$citizenship=="GN" & data$year_survey>1992 & data$cntry%in%Yes_Country_GN]<-3


#Ecuatorial Guinea --> no data online
data$first_year[data$citizenship=="GQ"]<-NA
data$VA_easy[data$citizenship=="GQ" & data$year_survey<2006]<-NA
data$VA_easy[data$citizenship=="GQ" & data$year_survey>2005]<-2

#Greece --> only EU election in 2014 --> coded as NO
data$first_year[data$citizenship=="GR"]<-2014
data$VA_easy[data$citizenship=="GR" & data$year_survey<2014]<-2
data$VA_easy[data$citizenship=="GR" & data$year_survey>2013]<-2
data$VA_easy[data$citizenship=="GR" & data$year_survey>2013 & data$cntry=="IS"]<-2


#Guatemala--> not yet implemented first elections in 2019, 2016 is when the law got changed
data$first_year[data$citizenship=="GT"]<-2016
data$VA_easy[data$citizenship=="GT" & data$year_survey<2016]<-1
data$VA_easy[data$citizenship=="GT" & data$year_survey>2015]<-2


#Guinea Bissau
#2014 --> http://www.undp.org/content/undp/en/home/presscenter/articles/2014/05/19/second-round-of-presidential-elections-in-guinea-bissau.html 
#2008 --> disenfranchized-->  https://eeas.europa.eu/sites/eeas/files/eu_eom_guinea_bissau_2008_-_final_report_eng.pdf

data$first_year[data$citizenship=="GW"]<-2014
data$VA_easy[data$citizenship=="GW" & data$year_survey<2014]<-2
data$VA_easy[data$citizenship=="GW" & data$year_survey>2013]<-2
Yes_Country_GW<-c("BE", "FR", "DE", "PT", "ES", "IS", "NL", "SI")
data$VA_easy[data$citizenship=="GW" & data$year_survey>2013 & data$cntry%in%Yes_Country_GW]<-3


#Guyana
#http://www.undp.org/content/dam/undp/library/Democratic%20Governance/Electoral%20Systems%20and%20Processes/Voting%20from%20Abroad%20in%2018%20Latin%20American%20Countries%20web%20version%20ENG.pdf
#Only special categories
data$first_year[data$citizenship=="GY"]<-1993
data$VA_easy[data$citizenship=="GY" & data$year_survey<1993]<-1
data$VA_easy[data$citizenship=="GY" & data$year_survey>1992]<-1


#Hong Kong
data$first_year[data$citizenship=="HK"]<-NA
data$VA_easy[data$citizenship=="HK" & data$year_survey<2016]<-0
data$VA_easy[data$citizenship=="HK" & data$year_survey>2015]<-0

#Honduras
#From LA Report only in the US
#https://www.elheraldo.hn/minisitios/hondurenosenelmundo/1273218-471/conviene-o-no-que-los-hondure%C3%B1os-puedan-votar-en-el-exterior
data$first_year[data$citizenship=="HN"]<-2001
data$VA_easy[data$citizenship=="HN" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="HN" & data$year_survey>2000]<-2

#Croatia
#https://www.osce.org/odihr/elections/croatia/41050?download=true
#https://www.osce.org/odihr/elections/croatia/42559?download=true
#http://eudo-citizenship.eu/admin/?p=file&appl=countryProfiles&f=135-Croatia-FRACIT.pdf
data$first_year[data$citizenship=="HR"]<-1992
data$VA_easy[data$citizenship=="HR" & data$year_survey<1992]<-NA
data$VA_easy[data$citizenship=="HR" & data$year_survey>1991]<-3
data$VA_easy[data$citizenship=="HR" & data$year_survey>1991 & data$cntry=="LU"]<-2


#Haiti
data$first_year[data$citizenship=="HT"]<-NA
data$VA_easy[data$citizenship=="HT" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="HT" & data$year_survey>2000]<-1

#Hungary
#https://www.washingtonpost.com/news/monkey-cage/wp/2014/04/14/the-2014-hungarian-parliamentary-elections-or-how-to-craft-a-constitutional-majority/?utm_term=.a335b1fcbc50
#https://budapestbeacon.com/twice-as-many-hungarians-living-abroad-likely-to-vote-in-2018-election-than-in-2014/
data$first_year[data$citizenship=="HU"]<-2004
data$VA_easy[data$citizenship=="HU" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="HU" & data$year_survey>2003]<-3
data$VA_easy[data$citizenship=="HU" & data$year_survey>2013]<-4

#Indonesia
#http://www.thejakartapost.com/news/2017/02/13/indonesians-abroad-return-to-vote-but-only-if-its-not-too-far.html
#https://aceproject.org/ace-en/topics/va/onePage

data$first_year[data$citizenship=="ID"]<-1955
data$VA_easy[data$citizenship=="ID" & data$year_survey<1955]<-0
data$VA_easy[data$citizenship=="ID" & data$year_survey>1954]<-4

#Ireland 
#only officials: http://www.pointofsinglecontact.ie/ireland-overview/who%20can%20vote%20in%20elections%20and%20referenda.pdf
#need to declear intention to return within 18 months: http://www.europarl.europa.eu/RegData/etudes/IDAN/2015/564379/EPRS_IDA(2015)564379_EN.pdf
data$first_year[data$citizenship=="IE"]<-1992
data$VA_easy[data$citizenship=="IE" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="IE" & data$year_survey>1991]<-2

#Israel
data$first_year[data$citizenship=="IL"]<-1969
data$VA_easy[data$citizenship=="IL" & data$year_survey<1969]<-1
data$VA_easy[data$citizenship=="IL" & data$year_survey>1968]<-2

#India
#In india only without double-citizenship: https://eci.nic.in/eci_main/nri/faq.pdf
#https://blogs.wsj.com/indiarealtime/2015/01/13/overseas-voting-in-indian-elections-what-to-know/
#https://blogs.wsj.com/indiarealtime/2011/02/04/non-resident-indians-may-get-to-vote/
#They still have to return home: https://blogs.wsj.com/indiarealtime/2015/01/13/overseas-voting-in-indian-elections-what-to-know/
#Now proxy: https://indianexpress.com/article/india/government-clears-proxy-vote-move-for-nris-4779759/
data$first_year[data$citizenship=="IN"]<-2014
data$VA_easy[data$citizenship=="IN" & data$year_survey<2014]<-1
data$VA_easy[data$citizenship=="IN" & data$year_survey>2013]<-2
data$VA_easy[data$citizenship=="IN" & data$year_survey>2018]<-3
data$VA_easy[data$citizenship=="IN" & data$year_survey>2018 & data$cntry=="LT"]<-2



#British Indian Ocean Territory 
data$first_year[data$citizenship=="IO"]<-NA
data$VA_easy[data$citizenship=="IO" & data$year_survey<1969]<-NA
data$VA_easy[data$citizenship=="IO" & data$year_survey>1968]<-NA

#Iraq 
#https://www.thenational.ae/world/mena/iraq-elections-2018-military-and-diaspora-begin-casting-their-votes-1.729105
#https://www.aljazeera.com/news/2018/05/uk-iraqis-disillusioned-political-process-vote-180505155759287.html
data$first_year[data$citizenship=="IQ"]<-2004
data$VA_easy[data$citizenship=="IQ" & data$year_survey<2004]<-0
data$VA_easy[data$citizenship=="IQ" & data$year_survey>2003]<-3
No_Country_IQ<-c("IL", "IS", "IE", "LT", "EE", "LU", "SI", "CY")
data$VA_easy[data$citizenship=="IQ" & data$year_survey>2003 & data$cntry%in%No_Country_IQ]<-2



#Iran 
#definitely in 2009: https://www.aljazeera.com/indepth/features/2012/02/201222075034498638.html
#https://foreignpolicyblogs.com/2013/01/03/a-critical-look-at-irans-out-of-country-voting-program/
data$first_year[data$citizenship=="IR"]<-2009
data$VA_easy[data$citizenship=="IR" & data$year_survey<2009]<-1
data$VA_easy[data$citizenship=="IR" & data$year_survey>2008]<-3
No_Country_IR<-c("EE", "IL", "IS", "LT", "LU")
data$VA_easy[data$citizenship=="IR" & data$year_survey>2008 & data$cntry%in%No_Country_IR]<-2


#Iceland
#For 8 years:https://www.island.is/en/homes_and_housing/change_of_residence/emigrating_abroad/
#https://www.government.is/publications/legislation/lex/?newsid=027e6a1a-f46b-11e7-9423-005056bc530c
data$first_year[data$citizenship=="IS"]<-2003
data$VA_easy[data$citizenship=="IS" & data$year_survey<2003]<-1
data$VA_easy[data$citizenship=="IS" & data$year_survey>2002]<-3


#Italy 
data$first_year[data$citizenship=="IT"]<-2003 #(referendum)
data$VA_easy[data$citizenship=="IT" & data$year_survey<2003]<-2
data$VA_easy[data$citizenship=="IT" & data$year_survey>2002]<-4


#Jamaica
#http://www.jamaicaobserver.com/columns/diaspora-voting-possible_56416
data$first_year[data$citizenship=="JM"]<-NA
data$VA_easy[data$citizenship=="JM" & data$year_survey<1969]<-1
data$VA_easy[data$citizenship=="JM" & data$year_survey>1968]<-1

#Jordan 
data$first_year[data$citizenship=="JO"]<-NA
data$VA_easy[data$citizenship=="JO" & data$year_survey<1969]<-1
data$VA_easy[data$citizenship=="JO" & data$year_survey>1968]<-1

#Japan
#Two steps --> 1998 in the PR part and 2006 also in the district (SMD)
data$first_year[data$citizenship=="JP"]<-2002
data$VA_easy[data$citizenship=="JP" & data$year_survey<2002]<-1
data$VA_easy[data$citizenship=="JP" & data$year_survey>2001]<-3


#Kenya
#Only where there are several residents (East Africa): http://www.mfa.go.ke/wp-content/uploads/2016/09/Kenya-Diaspora-Policy.pdf
#Hartmann 2015 says yes but it does not distinguish as I do between areas
data$first_year[data$citizenship=="KE"]<-2013
data$VA_easy[data$citizenship=="KE" & data$year_survey<2013]<-1
data$VA_easy[data$citizenship=="KE" & data$year_survey>2012]<-2

#Kyrgyz Rep
#https://www.osce.org/odihr/elections/329346?download=true
#Definitely 2017 (although many residents abroad did not register): https://www.osce.org/odihr/elections/kyrgyzstan/350001?download=true
data$first_year[data$citizenship=="KG"]<-2000
data$VA_easy[data$citizenship=="KG" & data$year_survey<2000]<-1
data$VA_easy[data$citizenship=="KG" & data$year_survey>1999]<-2
Yes_Country_KG<-c("BE", "DE", "RU", "TR", "UA", "GB", "CY", "FI", "HU", "IL", "NO", "SK", "CH", "AT")
data$VA_easy[data$citizenship=="KG" & data$year_survey>1999 & data$cntry%in%Yes_Country_KG]<-3


#Cambodia
data$first_year[data$citizenship=="KH"]<-NA
data$VA_easy[data$citizenship=="KH" & data$year_survey<1969]<-1
data$VA_easy[data$citizenship=="KH" & data$year_survey>1968]<-1

#Comoros 
data$first_year[data$citizenship=="KM"]<-2016
data$VA_easy[data$citizenship=="KM" & data$year_survey<2016]<-1
data$VA_easy[data$citizenship=="KM" & data$year_survey>2015]<-2
Yes_Country_KM<-c("BE", "FR", "IT", "TR", "UA", "GB")
data$VA_easy[data$citizenship=="KM" & data$year_survey>2015 & data$cntry%in%Yes_Country_KM]<-3


#Korea North
data$first_year[data$citizenship=="KP"]<-NA
data$VA_easy[data$citizenship=="KP" & data$year_survey<2016]<-0
data$VA_easy[data$citizenship=="KP" & data$year_survey>2015]<-0


#Korea South
#http://www.venice.coe.int/webforms/documents/default.aspx?pdffile=CDL(2011)027-e
data$first_year[data$citizenship=="KR"]<-2012
data$VA_easy[data$citizenship=="KR" & data$year_survey<2012]<-1
data$VA_easy[data$citizenship=="KR" & data$year_survey>2011]<-3
data$VA_easy[data$citizenship=="KR" & data$year_survey>2011 & data$cntry=="LT"]<-2

#Kuwait
data$first_year[data$citizenship=="KW"]<-NA
data$VA_easy[data$citizenship=="KW" & data$year_survey<2016]<-1
data$VA_easy[data$citizenship=="KW" & data$year_survey>2015]<-1


#Kazakstan
#https://www.osce.org/odihr/elections/kazakhstan/248781?download=true
data$first_year[data$citizenship=="KZ"]<-1994
data$VA_easy[data$citizenship=="KZ" & data$year_survey<1994]<-1
data$VA_easy[data$citizenship=="KZ" & data$year_survey>1993]<-3
No_Country_KZ<-c("CY", "LU")
data$VA_easy[data$citizenship=="KZ" & data$year_survey>1993 & data$cntry%in%No_Country_KZ]<-2


#Laos
#Yes personal but only in a few countries --> none of the ESS countries
data$first_year[data$citizenship=="LA"]<-2006
data$VA_easy[data$citizenship=="LA" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="LA" & data$year_survey>2005]<-2

#Lebanon
data$first_year[data$citizenship=="LB"]<-2018
data$VA_easy[data$citizenship=="LB" & data$year_survey<2018]<-1
data$VA_easy[data$citizenship=="LB" & data$year_survey>2017]<-3
No_Country_LB<-c("DK", "EE","FI", "HR", "IE", "IL", "IS", "LT", "LU" , "NO", "SI", "SK")
data$VA_easy[data$citizenship=="LB" & data$year_survey>2017 & data$cntry%in%No_Country_LB]<-2


#Liechtenstein
data$first_year[data$citizenship=="LI"]<-2004
data$VA_easy[data$citizenship=="LI" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="LI" & data$year_survey>2003]<-4

#Sri Lanka
data$first_year[data$citizenship=="LK"]<-NA
data$VA_easy[data$citizenship=="LK" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="LK" & data$year_survey>2005]<-1


#Liberia
#http://www.necliberia.org/doc_download/Final%20Amended%20Elections%20Law.pdf?a4705305cd27e04fb1f66830e7e0ef9d=Mw%3D%3D
data$first_year[data$citizenship=="LR"]<-2004
data$VA_easy[data$citizenship=="LR" & data$year_survey<2004]<-4
data$VA_easy[data$citizenship=="LR" & data$year_survey>2003]<-1

#Lithuania
#http://eudo-citizenship.eu/admin/?p=file&appl=countryProfiles&f=1320-Lithuania-FRACIT.pdf
data$first_year[data$citizenship=="LT"]<-1992
data$VA_easy[data$citizenship=="LT" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="LT" & data$year_survey>1991]<-4

#Luxemburg
data$first_year[data$citizenship=="LU"]<-1984
data$VA_easy[data$citizenship=="LU" & data$year_survey<1984]<-1
data$VA_easy[data$citizenship=="LU" & data$year_survey>1983]<-4

#Latvia
data$first_year[data$citizenship=="LV"]<-1992
data$VA_easy[data$citizenship=="LV" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="LV" & data$year_survey>1991]<-4

#Lybia
data$first_year[data$citizenship=="LY"]<-2012
data$VA_easy[data$citizenship=="LY" & data$year_survey<2012]<-0
data$VA_easy[data$citizenship=="LY" & data$year_survey>2011]<-3
No_Country_LY<-c("EE", "FI","IE", "IS", "IL" ,"LT", "LU", "NO", "SI")
data$VA_easy[data$citizenship=="LY" & data$year_survey>2011 & data$cntry%in%No_Country_LY]<-2


#Morocco
#https://www.moroccoworldnews.com/2016/07/191226/hassad-it-is-impossible-for-moroccans-abroad-to-vote-in-2016-elections/
data$first_year[data$citizenship=="MA"]<-2011
data$VA_easy[data$citizenship=="MA" & data$year_survey<2011]<-1
data$VA_easy[data$citizenship=="MA" & data$year_survey>2010]<-3
No_Country_MA<-c("IL", "IS", "LU")
data$VA_easy[data$citizenship=="MA" & data$year_survey>2010 & data$cntry%in%No_Country_MA]<-2



#Moldova
data$first_year[data$citizenship=="MD"]<-1993
data$VA_easy[data$citizenship=="MD" & data$year_survey<1993]<-1
data$VA_easy[data$citizenship=="MD" & data$year_survey>1992]<-3
No_Country_MD<-c("HR", "IE", "IS", "SI")
data$VA_easy[data$citizenship=="MD" & data$year_survey>1992 & data$cntry%in%No_Country_MD]<-2



#Madagascar
#Only for state employees
data$first_year[data$citizenship=="MG"]<-NA
data$VA_easy[data$citizenship=="MG" & data$year_survey<2011]<-1
data$VA_easy[data$citizenship=="MG" & data$year_survey>2010]<-2


#Macedonia
#https://www.repository.law.indiana.edu/cgi/viewcontent.cgi?article=1003&context=ijcd
#https://www.grin.com/document/295549
data$first_year[data$citizenship=="MK"]<-2009
data$VA_easy[data$citizenship=="MK" & data$year_survey<2009]<-1
data$VA_easy[data$citizenship=="MK" & data$year_survey>2008]<-3
No_Country_MK<-c("CY", "IE", "LT", "LU", "SK")
data$VA_easy[data$citizenship=="MK" & data$year_survey>2008 & data$cntry%in%No_Country_MK]<-2


#Mali
#http://www.mali-consulate.org.uk/#!/about consulate in the UK since 2012
#for consistency I use for all of them the value of 2018
data$first_year[data$citizenship=="ML"]<-1992
data$VA_easy[data$citizenship=="ML" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="ML" & data$year_survey>1991]<-2
Yes_Country_ML<-c("BE", "FR", "IT", "DE", "RU", "ES", "TR", "AT", "BG", "CY", "CZ", "FI", "GR", "LU", "SK", "CH", "SE", "GB")
data$VA_easy[data$citizenship=="ML" & data$year_survey>1991 & data$cntry%in%Yes_Country_ML]<-3


#Mongolia
#https://www.osce.org/odihr/elections/mongolia/271821?download=true
#Back and forth on the legislative elections, but yes for presidential
data$first_year[data$citizenship=="MN"]<-2012
data$VA_easy[data$citizenship=="MN" & data$year_survey<2012]<-1
data$VA_easy[data$citizenship=="MN" & data$year_survey>2011]<-3
data$VA_easy[data$citizenship=="MN" & data$year_survey>2011 & data$cntry=="LT"]<-2



#Macau
data$first_year[data$citizenship=="MO"]<-NA
data$VA_easy[data$citizenship=="MO" & data$year_survey<1992]<-NA
data$VA_easy[data$citizenship=="MO" & data$year_survey>1991]<-NA

#Mauritania
#https://freedomhouse.org/report/countries-crossroads/2007/mauritania
#https://tsep.africa.ufl.edu/the-electoral-system/mauritania/
#conflicting dates --> using first presidential election after coup
data$first_year[data$citizenship=="MR"]<-2009
data$VA_easy[data$citizenship=="MR" & data$year_survey<2009]<-1
data$VA_easy[data$citizenship=="MR" & data$year_survey>2008]<-2
Yes_Country_MR<-c("BE", "FR", "DE", "IT", "RU", "ES", "TR", "DK", "NL", "PT", "SE", "CH", "GB")
data$VA_easy[data$citizenship=="MR" & data$year_survey>2008 & data$cntry%in%Yes_Country_MR]<-3


#Malta
#very strict regulation of how much time spent, basically only temporary trips: http://www.europarl.europa.eu/RegData/etudes/IDAN/2015/564379/EPRS_IDA(2015)564379_EN.pdf
data$first_year[data$citizenship=="MT"]<-NA
data$VA_easy[data$citizenship=="MT" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="MT" & data$year_survey>1991]<-1

#Mauritius
#http://electoral.govmu.org/English/Faqs/Pages/default.aspx
#By proxy and only for officials and families
data$first_year[data$citizenship=="MU"]<-NA
data$VA_easy[data$citizenship=="MU" & data$year_survey<1992]<-2
data$VA_easy[data$citizenship=="MU" & data$year_survey>1991]<-2


#Maldives
#http://www.eeas.europa.eu/archives/eueom/pdf/missions/eueemtothemaldivesfinalreport2nddraft.pdf
#only in Trivandrum, Colombo, Singapore and Kuala Lumpur.
data$first_year[data$citizenship=="MV"]<-2008
data$VA_easy[data$citizenship=="MV" & data$year_survey<2008]<-1
data$VA_easy[data$citizenship=="MV" & data$year_survey>2007]<-2

#Malawi
data$first_year[data$citizenship=="MW"]<-NA
data$VA_easy[data$citizenship=="MW" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="MW" & data$year_survey>1991]<-1

#Mexico
#https://www.dw.com/en/mexican-voters-abroad-hold-more-sway-than-ever-before/av-44463890
#http://www.votoextranjero.mx/web/vmre/historico
#evote in municipalities and governor in 2012: https://www.sciencedirect.com/science/article/pii/S0041863318300085
data$first_year[data$citizenship=="MX"]<-2006
data$VA_easy[data$citizenship=="MX" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="MX" & data$year_survey>2005 & data$year_survey<2012]<-4
data$VA_easy[data$citizenship=="MX" & data$year_survey>2011]<-5

#Malaysia
#https://asklegal.my/p/postal-vote-election-malaysia-GE14-overseas-absent-ordinary-voter
data$first_year[data$citizenship=="MY"]<-2013
data$VA_easy[data$citizenship=="MY" & data$year_survey<2013]<-2
data$VA_easy[data$citizenship=="MY" & data$year_survey>2012]<-4


#Mozambique
data$first_year[data$citizenship=="MZ"]<-2004
data$VA_easy[data$citizenship=="MZ" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="MZ" & data$year_survey>2003]<-2
Yes_Country_MZ<-c("BE", "FR", "DE", "IT", "PT", "RU", "SE", "ES", "GB", "AT", "IL", "CH", "GB")
data$VA_easy[data$citizenship=="MZ" & data$year_survey>2003 & data$cntry%in%Yes_Country_MZ]<-3


#Niger
#data about vote abroad found on wikipedia for 2016
#http://archive.ipu.org/parline-e/reports/2237_B.htm 
data$first_year[data$citizenship=="NE"]<-2016
data$VA_easy[data$citizenship=="NE" & data$year_survey<2016]<-1
data$VA_easy[data$citizenship=="NE" & data$year_survey>2015]<-4

#Nigeria
#lots of debate happening but no vote
data$first_year[data$citizenship=="NG"]<-NA
data$VA_easy[data$citizenship=="NG" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="NG" & data$year_survey>2003]<-1

#Nicaragua
#https://www.laprensa.com.ni/2016/11/01/politica/2126678-nicaraguenses-voto-exterior
#there is the law but it is not applied!
data$first_year[data$citizenship=="NI"]<-NA
data$VA_easy[data$citizenship=="NI" & data$year_survey<2004]<-2
data$VA_easy[data$citizenship=="NI" & data$year_survey>2003]<-2

#Netherland
data$first_year[data$citizenship=="NL"]<-1989
data$VA_easy[data$citizenship=="NL" & data$year_survey<1989]<-1
data$VA_easy[data$citizenship=="NL" & data$year_survey>1988]<-4

#Norway
data$first_year[data$citizenship=="NO"]<-1921
data$VA_easy[data$citizenship=="NO" & data$year_survey<1921]<-1
data$VA_easy[data$citizenship=="NO" & data$year_survey>1920]<-4

#Nepal
data$first_year[data$citizenship=="NP"]<-NA
data$VA_easy[data$citizenship=="NP" & data$year_survey<1989]<-1
data$VA_easy[data$citizenship=="NP" & data$year_survey>1988]<-1

#New Zealand
#https://www.elections.org.nz/voters/get-ready-enrol-and-vote/enrol-and-vote-overseas
data$first_year[data$citizenship=="NZ"]<-1993
data$VA_easy[data$citizenship=="NZ" & data$year_survey<1993]<-1
data$VA_easy[data$citizenship=="NZ" & data$year_survey>1992]<-4

#Panama
data$first_year[data$citizenship=="PA"]<-2009
data$VA_easy[data$citizenship=="PA" & data$year_survey<2009]<-1
data$VA_easy[data$citizenship=="PA" & data$year_survey>2008 & data$year_survey<2014]<-4
data$VA_easy[data$citizenship=="PA" & data$year_survey>2013 ]<-5


#Peru
data$first_year[data$citizenship=="PE"]<-1980
data$VA_easy[data$citizenship=="PE" & data$year_survey<1980]<-1
data$VA_easy[data$citizenship=="PE" & data$year_survey>1979]<-3
No_Country_PE<-c("LT", "LU")
data$VA_easy[data$citizenship=="PE" & data$year_survey>1979 & data$cntry%in%No_Country_PE]<-2


#Philippines
data$first_year[data$citizenship=="PH"]<-2004
data$VA_easy[data$citizenship=="PH" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="PH" & data$year_survey>2003]<-4

#Pakistan
data$first_year[data$citizenship=="PK"]<-NA
data$VA_easy[data$citizenship=="PK" & data$year_survey<1989]<-1
data$VA_easy[data$citizenship=="PK" & data$year_survey>1988]<-1

#Poland
#at least 15 people per circuit
data$first_year[data$citizenship=="PL"]<-1990
data$VA_easy[data$citizenship=="PL" & data$year_survey<1990]<-1
data$VA_easy[data$citizenship=="PL" & data$year_survey>1989]<-4

#Puerto Rico --> same as USA
data$first_year[data$citizenship=="PR"]<-1942
data$VA_easy[data$citizenship=="PR" & data$year_survey<1942]<-1
data$VA_easy[data$citizenship=="PR" & data$year_survey>1942 & data$year_survey<2000 ]<-4
data$VA_easy[data$citizenship=="PR" & data$year_survey>2000]<-5

#Palestine
data$first_year[data$citizenship=="PS"]<-NA
data$VA_easy[data$citizenship=="PS" & data$year_survey<1990]<-1
data$VA_easy[data$citizenship=="PS" & data$year_survey>1989]<-1

#Portugal
data$first_year[data$citizenship=="PT"]<-1975
data$VA_easy[data$citizenship=="PT" & data$year_survey<1975]<-1
data$VA_easy[data$citizenship=="PT" & data$year_survey>1974]<-4

#Paraguay

#https://www.ip.gov.py/ip/unos-38-000-paraguayos-estan-habilitados-para-votar-desde-el-exterior/
#http://www.abc.com.py/nacionales/donde-votar-en-el-exterior-1693348.html

data$first_year[data$citizenship=="PY"]<-2013
data$VA_easy[data$citizenship=="PY" & data$year_survey<2013]<-1
data$VA_easy[data$citizenship=="PY" & data$year_survey>2012]<-2
data$VA_easy[data$citizenship=="PE" & data$year_survey>2012 & data$cntry=="ES"]<-3


#Reunion --> same as France
data$first_year[data$citizenship=="RE"]<-1926
data$VA_easy[data$citizenship=="RE" & data$year_survey<2012 & data$year_survey>1974 ]<-3
data$VA_easy[data$citizenship=="RE" & data$year_survey>1926 & data$year_survey<1975]<-4
data$VA_easy[data$citizenship=="RE" & data$year_survey>2011 & data$year_survey<2017]<-5
data$VA_easy[data$citizenship=="RE" & data$year_survey>2016]<-3

#Romania
#https://www.osce.org/odihr/elections/romania/278346?download=true
data$first_year[data$citizenship=="RO"]<-1990
data$VA_easy[data$citizenship=="RO" & data$year_survey<1990]<-1
data$VA_easy[data$citizenship=="RO" & data$year_survey>1989 &  data$year_survey<2015]<-3
data$VA_easy[data$citizenship=="RO" & data$year_survey>2014]<-4



#Serbia
data$first_year[data$citizenship=="RS"]<-NA
data$VA_easy[data$citizenship=="RS" & data$year_survey<2017]<-1
data$VA_easy[data$citizenship=="RS" & data$year_survey>2016]<-1

#Russia
#sluslov
#2012-2018 http://intersectionproject.eu/article/politics/russian-presidential-elections-outside-russia
# 2016 https://www.osce.org/odihr/elections/russia/251486?download=true
#2007 https://www.loc.gov/law/help/parliamentary-elections/russia-parliamentary-elections.pdf
#2012 http://tass.com/politics/994986

data$first_year[data$citizenship=="RU"]<-2007
data$VA_easy[data$citizenship=="RU" & data$year_survey<2007]<-1
data$VA_easy[data$citizenship=="RU" & data$year_survey>2006]<-3

#Rwanda
#https://www.voanews.com/a/rwandan-overseas-voting/3970673.html
data$first_year[data$citizenship=="RW"]<-2003
data$VA_easy[data$citizenship=="RW" & data$year_survey<2003]<-1
data$VA_easy[data$citizenship=="RW" & data$year_survey>2002]<-2
Yes_Country_RW<-c("BE", "FR", "DE", "IL", "NL", "SE", "GB", "TR", "RU", "CY", "IT", "LU", "NO", "CH")
data$VA_easy[data$citizenship=="RW" & data$year_survey>2002 & data$cntry%in%Yes_Country_RW]<-3

#Saudi Arabia
data$first_year[data$citizenship=="SA"]<-NA
data$VA_easy[data$citizenship=="SA" & data$year_survey<2003]<-0
data$VA_easy[data$citizenship=="SA" & data$year_survey>2002]<-0

#Sudan
#https://www.aljazeera.com/news/2015/04/sudanese-expatriates-apathetic-presidential-vote-150419084902992.html
data$first_year[data$citizenship=="SD"]<-1986
data$VA_easy[data$citizenship=="SD" & data$year_survey<1986]<-1
data$VA_easy[data$citizenship=="SD" & data$year_survey>1985]<-3
No_Country_SD<-c("BG", "CY", "EE", "HU", "IS","LT", "IL", "LU", "PL", "SI", "SK")
data$VA_easy[data$citizenship=="SD" & data$year_survey>1985 & data$cntry%in%No_Country_SD]<-2

#Sweden
data$first_year[data$citizenship=="SE"]<-1968
data$VA_easy[data$citizenship=="SE" & data$year_survey<1968]<-1
data$VA_easy[data$citizenship=="SE" & data$year_survey>1967]<-4


#Singapure
#https://www.mfa.gov.sg/content/mfa/overseasmission/bangkok/announcements/information_on_overseas_voting_20150908.html
#It could be a 3 but there are only 10 polling stations and only in the UK among the countries we care about here
#List of places: http://www.eld.gov.sg/voters_ops.html
data$first_year[data$citizenship=="SG"]<-2006
data$VA_easy[data$citizenship=="SG" & data$year_survey<2006]<-1
data$VA_easy[data$citizenship=="SG" & data$year_survey>2005]<-2
data$VA_easy[data$citizenship=="SG" & data$year_survey>2005 & data$cntry=="GB"]<-3


#Saint Helena
#could not find data
data$first_year[data$citizenship=="SH"]<-2009
data$VA_easy[data$citizenship=="SH" & data$year_survey<2009]<-1
data$VA_easy[data$citizenship=="SH" & data$year_survey>2008]<-2
data$VA_easy[data$citizenship=="SH" & data$year_survey>2008 & data$cntry=="GB"]<-3



#Slovenia
data$first_year[data$citizenship=="SI"]<-1992
data$VA_easy[data$citizenship=="SI" & data$year_survey<1992]<-0
data$VA_easy[data$citizenship=="SI" & data$year_survey>1992]<-4


#Slovakia
#https://europa.eu/youreurope/citizens/residence/elections-abroad/home-country-elections/slovakia/index_en.htm
data$first_year[data$citizenship=="SK"]<-2004
data$VA_easy[data$citizenship=="SK" & data$year_survey<2004]<-1
data$VA_easy[data$citizenship=="SK" & data$year_survey>2003]<-4


#Sierra Leone
data$first_year[data$citizenship=="SL"]<-2012
data$VA_easy[data$citizenship=="SL" & data$year_survey<2012]<-1
data$VA_easy[data$citizenship=="SL" & data$year_survey>2011]<-2

#San Marino
#http://www.esteri.sm/on-line/home/corpo-diplomatico-e-consolare-sammarinese.html
data$first_year[data$citizenship=="SM"]<-NA
data$VA_easy[data$citizenship=="SM" & data$year_survey<2012]<-1
data$VA_easy[data$citizenship=="SM" & data$year_survey>2011]<-1


#Senegal
#if at least 200 of them register with diplomatic missions in the foreign country: https://www.sec.gouv.sn/sites/default/files/loisetdecrets/Loi%20n°%202017-12%20du%2018%20janvier%202017%20portant%20Code%20électoral.pdf
#Hartmann says "limited requirements
data$first_year[data$citizenship=="SN"]<-1992
data$VA_easy[data$citizenship=="SN" & data$year_survey<1992]<-1
data$VA_easy[data$citizenship=="SN" & data$year_survey>1991]<-2

#Somalia
data$first_year[data$citizenship=="SO"]<-NA
data$VA_easy[data$citizenship=="SO" & data$year_survey<2012]<-0
data$VA_easy[data$citizenship=="SO" & data$year_survey>2011]<-0


##Suriname
data$first_year[data$citizenship=="SR"]<-NA
data$VA_easy[data$citizenship=="SR" & data$year_survey<2012]<-1
data$VA_easy[data$citizenship=="SR" & data$year_survey>2011]<-1

#Sao Tome and Principe
#https://au.int/sites/default/files/newsevents/reports/31096-rp-aueom_stp_preliminary_statement_eng-2.pdf
#Idea says not yet implemented, Hartmann says yes, source above from 2016 confirmed improvements had been done
data$first_year[data$citizenship=="ST"]<-1990
data$VA_easy[data$citizenship=="ST" & data$year_survey<1990]<-1
data$VA_easy[data$citizenship=="ST" & data$year_survey>1989 & data$year_survey<2016]<-2
data$VA_easy[data$citizenship=="ST" & data$year_survey>2015]<-2
Yes_Country_ST<-c("BE", "PT", "AT", "FR", "GR", "DE", "HU", "ES")
data$VA_easy[data$citizenship=="ST" & data$year_survey>2015 & data$cntry%in%Yes_Country_ST]<-3

#USSR
data$first_year[data$citizenship=="SU"]<-NA
data$VA_easy[data$citizenship=="SU" ]<-1


#El Salvador
#https://www.tse.gob.sv/noticia/2018/La-ciudadan%C3%ADa-residente-en-el-exterior-ya-puede-empadronarse-para-votar-en-2019
data$first_year[data$citizenship=="SV"]<-2014
data$VA_easy[data$citizenship=="SV" & data$year_survey<2014]<-1
data$VA_easy[data$citizenship=="SV" & data$year_survey>2013]<-4



##Syria
#https://www.dw.com/en/syrian-refugees-vote-or-dont-from-abroad/a-17678328
#https://www.reuters.com/article/us-syria-crisis-election/tens-of-thousands-of-syrians-abroad-vote-in-early-poll-idUSKBN0E815R20140528
#https://www.timesofisrael.com/thousands-of-syrian-refugees-flock-to-embassies-to-vote/
#unclear when it started
data$first_year[data$citizenship=="SY"]<-NA
data$VA_easy[data$citizenship=="SY"]<-2
Yes_Country_SY<-c("AT", "BE", "BG", "CY", "CZ", "FR", "DE", "GR", "HU", "IT", "PL", "RU", "ES", "SE", "TR", "GB", "UA", "HR", "SK", "CH")
data$VA_easy[data$citizenship=="SY"  & data$cntry%in%Yes_Country_SY]<-3

#Chad
data$first_year[data$citizenship=="TD"]<-2001
data$VA_easy[data$citizenship=="TD" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="TD" & data$year_survey>2002]<-2
Yes_Country_TD<-c("BE", "FR", "DE", "RU", "TR", "AT", "DK", "GR", "LU", "NL", "CH")
data$VA_easy[data$citizenship=="TD" & data$year_survey>2002 & data$cntry%in%Yes_Country_TD]<-3

#Togo
#Hartman says yes since 2005, Idea.int says not implemented
data$first_year[data$citizenship=="TG"]<-2005
data$VA_easy[data$citizenship=="TG" & data$year_survey<2005]<-1
data$VA_easy[data$citizenship=="TG" & data$year_survey>2004]<-2
Yes_Country_TG<-c("BE", "FR", "DE", "GB", "AT", "DK", "IS", "IT", "LU", "NL", "ES", "CH")
data$VA_easy[data$citizenship=="TG" & data$year_survey>2004 & data$cntry%in%Yes_Country_TG]<-3


#Thailand
#If more than 500 people, personal, less postal
#https://www.bangkokpost.com/news/politics/740212/thai-expats-to-register-online-to-vote
data$first_year[data$citizenship=="TH"]<-2000
data$VA_easy[data$citizenship=="TH" & data$year_survey<2000]<-1
data$VA_easy[data$citizenship=="TH" & data$year_survey>1999]<-3


#Tajikistan
#https://www.osce.org/odihr/elections/tajikistan/104054?download=true
data$first_year[data$citizenship=="TJ"]<-1994
data$VA_easy[data$citizenship=="TJ" & data$year_survey<1994]<-1
data$VA_easy[data$citizenship=="TJ" & data$year_survey>1993]<-2
Yes_Country_TJ<-c("BE", "AT", "FR", "DE", "RU", "TR", "UA", "GB", "CH")
data$VA_easy[data$citizenship=="TJ" & data$year_survey>1993 & data$cntry%in%Yes_Country_TJ]<-3

#Timor-Leste
data$first_year[data$citizenship=="TL"]<-1999
data$VA_easy[data$citizenship=="TL" & data$year_survey<1999]<-NA
data$VA_easy[data$citizenship=="TL" & data$year_survey>1998 & data$year_survey<2017]<-2
data$VA_easy[data$citizenship=="TL" & data$year_survey>2016]<-2
Yes_Country_TL<-c("BE", "PT", "GB", "DE", "IE")
data$VA_easy[data$citizenship=="TL" & data$year_survey>2016 & data$cntry%in%Yes_Country_TL]<-3

#Turkmenistan
data$first_year[data$citizenship=="TM"]<-2008
data$VA_easy[data$citizenship=="TM" & data$year_survey<2008]<-1
data$VA_easy[data$citizenship=="TM" & data$year_survey>2007 & data$year_survey<2012]<-2
data$VA_easy[data$citizenship=="TM" & data$year_survey>2011]<-3
Yes_Country_TM<-c("AT", "BE", "FR", "DE", "IT", "RU", "TR", "UA", "GB", "IL")
data$VA_easy[data$citizenship=="TM" & data$year_survey>2011 & data$cntry%in%Yes_Country_TM]<-3


#Tunisia
#Jaulin 2016
#New electoral law after 2011 creates seats for residents abroad
#Idea int different date--> unclear from where
data$first_year[data$citizenship=="TN"]<-1989
data$VA_easy[data$citizenship=="TN" & data$year_survey<1989]<-1
data$VA_easy[data$citizenship=="TN" & data$year_survey>1988]<-2
Yes_Country_TN<-c("AT", "BE", "CZ", "FI", "FR", "DE", "GR", "HU", "IT", "NL", "NO", "PO", "PT", "RU", "ES", "SE", "CH", "TR", "GB", "HR", "CY", "DK", "IE", "LU", "UA")
data$VA_easy[data$citizenship=="TN" & data$year_survey>1988 & data$cntry%in%Yes_Country_TN]<-3


#Turkey
#Until 2014 only at the border so classified as 2
#Idea.int says e-voting but could not find evidence of that anywhere
#Sahin_Mencutek 2015
#https://www.dailysabah.com/elections/2018/05/13/turkish-citizens-living-abroad-to-vote-in-60-countries-in-upcoming-elections for where
data$first_year[data$citizenship=="TR"]<-1987
data$VA_easy[data$citizenship=="TR" & data$year_survey<1987]<-1
data$VA_easy[data$citizenship=="TR" & data$year_survey>1986 & data$year_survey<2014]<-2
data$VA_easy[data$citizenship=="TR" & data$year_survey>2013]<-3
No_Country_TR<-c("CY", "HR", "SI", "SK", "IS", "LT", "PT")
data$VA_easy[data$citizenship=="TR" & data$year_survey>2013 & data$cntry%in%No_Country_TR]<-2


#Tanzania
#agreement both Hartmann and Idea
data$first_year[data$citizenship=="TZ"]<-NA
data$VA_easy[data$citizenship=="TZ" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="TZ" & data$year_survey>2002]<-1


#Ukraine
#Idea and Venice_UE report
data$first_year[data$citizenship=="UA"]<-1994
data$VA_easy[data$citizenship=="UA" & data$year_survey<1994]<-1
data$VA_easy[data$citizenship=="UA" & data$year_survey>1993]<-3
#checked, all emabassies/consulate in the sample


#Uganda
#agreement both Hartmann and Idea
data$first_year[data$citizenship=="UG"]<-NA
data$VA_easy[data$citizenship=="UG" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="UG" & data$year_survey>2002]<-1


#US
data$first_year[data$citizenship=="US"]<-1942
data$VA_easy[data$citizenship=="US" & data$year_survey<1942]<-1
data$VA_easy[data$citizenship=="US" & data$year_survey>1942 & data$year_survey<2000]<-4
data$VA_easy[data$citizenship=="US" & data$year_survey>1999]<-5


#Uruguay
data$first_year[data$citizenship=="UY"]<-NA
data$VA_easy[data$citizenship=="UY" ]<-1


#Uzbekistan
#Only where there are embassies (from https://mfa.uz/en/about/missions/):
data$first_year[data$citizenship=="UZ"]<-1994
data$VA_easy[data$citizenship=="UZ" & data$year_survey<1994]<-1
data$VA_easy[data$citizenship=="UZ" & data$year_survey>1993]<-2
Yes_Country_UZ<-c("ES", "GB", "AT", "FR", "DE", "GR", "IT", "IL", "LV", "RU", "PL" ,"UA", "BE", "BY", "TR")
data$VA_easy[data$citizenship=="UZ" & data$year_survey>1993 & data$cntry%in%Yes_Country_UZ]<-3


#Venezuela
#For example: Ukraine embassy of reference for Venezuela is in Cuba
data$first_year[data$citizenship=="VE"]<-1998
data$VA_easy[data$citizenship=="VE" & data$year_survey<1998]<-1
data$VA_easy[data$citizenship=="VE" & data$year_survey>1997]<-3
No_Country_VE<-c("CY", "CZ", "EE", "FI", "IS", "HR", "IE", "LT", "LU", "SK", "UA")
data$VA_easy[data$citizenship=="VE" & data$year_survey>1997 & data$cntry%in%No_Country_VE]<-2


#Viet Nam
data$first_year[data$citizenship=="VN"]<-NA
data$VA_easy[data$citizenship=="VN" & data$year_survey<1998]<-1
data$VA_easy[data$citizenship=="VN" & data$year_survey>1997]<-1


#Kosovo
data$first_year[data$citizenship=="XK"]<-2008
data$VA_easy[data$citizenship=="XK" & data$year_survey<2008]<-0
data$VA_easy[data$citizenship=="XK" & data$year_survey>2007]<-4

#Yemen
data$first_year[data$citizenship=="YE"]<-2001
data$VA_easy[data$citizenship=="YE" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="YE" & data$year_survey>2000]<-2

#Yugoslavia
#classified as 0 since the country does not exist anymore
data$first_year[data$citizenship=="YU"]<-NA
data$VA_easy[data$citizenship=="YU" ]<-0

#South Africa
data$first_year[data$citizenship=="ZA"]<-1994
data$VA_easy[data$citizenship=="ZA" & data$year_survey<1994]<-1
data$VA_easy[data$citizenship=="ZA" & data$year_survey>1993]<-3
No_Country_ZA<-c("CY", "LT")
data$VA_easy[data$citizenship=="ZA" & data$year_survey>1993 & data$cntry%in%No_Country_ZA]<-2

#Zambia
data$first_year[data$citizenship=="ZM"]<-NA
data$VA_easy[data$citizenship=="ZM" & data$year_survey<2001]<-1
data$VA_easy[data$citizenship=="ZM" & data$year_survey>2000]<-1


#Zimbabwe
#https://www.dw.com/en/zimbabwe-court-shatters-diaspora-voting-hopes/a-44006144
#Hartmann --> only state employees
data$first_year[data$citizenship=="ZW"]<-2008
data$VA_easy[data$citizenship=="ZW" & data$year_survey<2008]<-1
data$VA_easy[data$citizenship=="ZW" & data$year_survey>2007]<-2

#VA _easy dichotmous

data$VA_easy_1<-rep(NA, nrow(data))
data$VA_easy_1[which(data$VA_easy<3)]<-0
data$VA_easy_1[which(data$VA_easy>2)]<-1

table(data$VA_easy_1, data$VA_easy)

sort(unique(data$year_survey))

######################################
##############Other VARIABLES   #######
#######################################

#REGIONS of HOST

data$region<-c()
data$region[data$cntry%in%c("AT", "BE", "CH", "DE", "FR", "NL", "LU")]<-"Center Europe"
data$region[data$cntry%in%c("DK", "NO", "SE", "FI", "IS")]<-"Nordic Countries"
data$region[data$cntry%in%c("ES", "IT", "IL", "PT" )]<-"South Europe"
data$region[data$cntry%in%c("CY", "GR", "TR", "SI" , "HR")]<-"Balkans and SE Europe"
data$region[data$cntry%in%c("BG", "EE", "SK", "RU", "HU", "CZ", "PL", "UA"  )]<-"East Europe"
data$region[data$cntry%in%c("GB", "IE" )]<-"GB and IE"

plotmeans(data$VA_easy_1~data$region)
plotmeans(data$VA_easy~data$essround)

length(unique(data$cntry))#32
length(unique(data$citizenship))#176


plotmeans(data$VA_easy_1~data$cntry)


#####CUSTOMS: Important to follow traditions and customs imptrad
#Very much like me to Not like me at all
#Vignette: "Tradition is important to her/him. She/he tries to follow the customs handed down by her/his religion or her/his family."

data$imptrad_num<-as.numeric(data$imptrad)
data$imptrad_num[which(data$imptrad_num>6)]<-NA
summary(data$imptrad_num)
table(data$imptrad_num, data$imptrad)

#Household size
data$hhmmb[which(data$hhmmb>70)]<-NA

#Language spoken at home --> same as the host country language
data$same_language<-rep(1, nrow(data))
data$same_language[which(data$lnghoma==NA)]<-NA
data$same_language[data$cntry=="AT" & (data$lnghoma=="GER" | data$lnghom1=="GER")]<-0
data$same_language[data$cntry=="BE" & (data$lnghoma%in%c("DUT", "FRE", "GER")  | data$lnghom1%in%c("DUT", "FRE", "GER"))]<-0
data$same_language[data$cntry=="BG"& (data$lnghoma=="BUL"  | data$lnghom1=="BUL")]<-0
data$same_language[data$cntry=="CH"& (data$lnghoma%in%c("FRE", "GER", "ITA", "GSW", "ROH")  | data$lnghom1%in%c("FRE", "GER", "ITA", "GSW", "ROH"))]<-0
data$same_language[data$cntry=="CY"& (data$lnghoma%in%c("TUR", "GRE")  | data$lnghom1%in%c("TUR", "GRE"))]<-0
data$same_language[data$cntry=="CZ"& (data$lnghoma=="CZE"  | data$lnghom1=="CZE")]<-0
data$same_language[data$cntry=="DE"& (data$lnghoma%in%c("GER", "NDS")  | data$lnghom1%in%c("GER", "NDS"))]<-0
data$same_language[data$cntry=="DK"& (data$lnghoma=="DAN"  | data$lnghom1=="DAN")]<-0
data$same_language[data$cntry=="EE"& (data$lnghoma=="EST" | data$lnghom1=="EST")]<-0
data$same_language[data$cntry=="ES"& (data$lnghoma%in%c("SPA", "CAT", "BAQ", "GLG")  | data$lnghom1%in%c("SPA", "CAT", "BAQ", "GLG")  )]<-0
data$same_language[data$cntry=="FI"& (data$lnghoma%in%c("FIN", "FIU")  | data$lnghom1%in%c("FIN", "FIU"))]<-0
data$same_language[data$cntry=="FR"& (data$lnghoma=="FRE"  | data$lnghom1=="FRE")]<-0
data$same_language[data$cntry=="GB"& (data$lnghoma%in%c("ENG", "GLA", "GLE", "SCO", "WEL")  | data$lnghom1%in%c("ENG", "GLA", "GLE", "SCO", "WEL"))]<-0
data$same_language[data$cntry=="HR"& (data$lnghoma%in%c("SCR", "SRP", "SCC", "HRV")  | data$lnghom1%in%c("SCR", "SRP", "SCC", "HRV") )]<-0
data$same_language[data$cntry=="HU"& (data$lnghoma=="HUN"  | data$lnghom1=="HUN")]<-0
data$same_language[data$cntry=="IE"& (data$lnghoma=="GLE"  | data$lnghom1=="GLE")]<-0
data$same_language[data$cntry=="IL"& (data$lnghoma=="HEB"  | data$lnghom1=="HEB")]<-0
data$same_language[data$cntry=="IS"& (data$lnghoma=="ICE"  | data$lnghom1=="ICE")]<-0
data$same_language[data$cntry=="IT"& (data$lnghoma%in%c("ITA", "SRD", "SCN")  | data$lnghom1%in%c("ITA", "SRD", "SCN") )]<-0
data$same_language[data$cntry=="LT"& (data$lnghoma=="LIT"  | data$lnghom1=="LIT")]<-0
data$same_language[data$cntry=="LU"& (data$lnghoma%in%c("LTZ", "FRE", "GER")  | data$lnghom1%in%c("LTZ", "FRE", "GER") )]<-0
data$same_language[data$cntry=="NL"& (data$lnghoma%in%c("DUT", "ENG", "PAP", "FRY")  | data$lnghom1%in%c("DUT", "ENG", "PAP", "FRY"))]<-0
data$same_language[data$cntry=="NO"& (data$lnghoma%in%c("NNO", "NOR", "NOB", "SOT", "NON")  | data$lnghom1%in%c("NNO", "NOR", "NOB", "SOT", "NON") )]<-0
data$same_language[data$cntry=="PL"& (data$lnghoma=="POL"  | data$lnghom1=="POL")]<-0
data$same_language[data$cntry=="PT"& (data$lnghoma=="POR" | data$lnghom1=="POR")]<-0
data$same_language[data$cntry=="RU"& (data$lnghoma=="RUS"  | data$lnghom1=="RUS")]<-0
data$same_language[data$cntry=="SE"& (data$lnghoma=="SWE"  | data$lnghom1=="SWE")]<-0
data$same_language[data$cntry=="SI"& (data$lnghoma=="SLV"  | data$lnghom1=="SLV")]<-0
data$same_language[data$cntry=="SK"& (data$lnghoma=="SLO"  | data$lnghom1=="SLO")]<-0
data$same_language[data$cntry=="TR"& (data$lnghoma=="TUR"  | data$lnghom1=="TUR")]<-0
data$same_language[data$cntry=="UA"& (data$lnghoma=="UKR"  | data$lnghom1=="UKR")]<-0



#Education

data$eduyrs_num<-as.numeric(data$eduyrs)
data$eduyrs_num[data$eduyrs_num>76]<-NA
summary(data$eduyrs_num)


#Paid Work
unique(data$pdwrk)



#Political Interest
data$polintr_num1<-as.numeric(data$polintr) #reversing the order so that higher =more interest
data$polintr_num[which(data$polintr_num1==4)]<-1
data$polintr_num[which(data$polintr_num1==3)]<-2
data$polintr_num[which(data$polintr_num1==2)]<-3
data$polintr_num[which(data$polintr_num1==1)]<-4
data$polintr_num[as.numeric(data$polintr)>4]<-NA
unique(data$polintr)
table(data$polintr,data$polintr_num)

#Pol interest dummy

data$pol_int_dummy<-ifelse(data$polintr_num>2, 1, 0)
data$pol_int_dummy[as.numeric(data$polintr)>4]<-NA

#Pol Interest dummy 2
data$pol_int_dummy2<-ifelse(data$polintr_num>1, 1, 0)
data$pol_int_dummy2[as.numeric(data$polintr)>4]<-NA



#Tv politics
data$tvpol_num<-as.numeric(data$tvpol)
data$tvpol_num[as.numeric(data$tvpol)>8]<-NA


data$nwsppol_num<-as.numeric(data$nwsppol)
data$nwsppol_num[as.numeric(data$nwsppol)>8]<-NA


data$rdpol_num<-as.numeric(data$rdpol)
data$rdpol_num[as.numeric(data$rdpol)>8]<-NA

table(data$rdpol_num)

#NEws

data$news<-rep(NA, nrow(data))

table(data$tvpol)

for (i in 1:nrow(data)){
#i<-15	
data$news[i]<-ifelse(sum(data$tvpol_num[i], data$rdpol_num[i], data$nwsppol_num[i], na.rm=T)>0, mean(c(data$tvpol_num[i], data$rdpol_num[i], data$nwsppol_num[i]), na.rm=T), NA)
print(i)
}



#discrimination

data$dscrgrp_num1<-as.numeric(data$dscrgrp)
data$dscrgrp_num<-ifelse(data$dscrgrp_num1==2, 0, data$dscrgrp_num1)
data$dscrgrp_num<-ifelse(data$dscrgrp_num1>2, NA, data$dscrgrp_num)

table(data$dscrgrp_num, data$dscrgrp)



#or non-WEstern Europe
EU<-c("AT", "BE", "DE", "DK", "ES", "FI", "FR", "GB", "GR", "IE", "IT", "LU", "NL", "PT", "SE") 

West_eu<-c("AT", "BE", "DE", "DK", "ES", "FI", "FR", "GB", "GR", "IE", "IT", "LU", "NL", "PT", "SE", "CH", "NO", "IS") 

data$Non_westernEU<-ifelse(data$citizenship%in%West_eu, 0, 1)


########GROUPING OF CITIZENSHIP




#1. West Eu, Non-west Eu, Central ASia, Russia, Africa, Middle-east, East ASia, South ASia, Latin America


North_West_eu<-c("AT", "BE", "DE", "DK", "FI", "FR", "LU", "NL", "SE", "CH", "NO", "IS", "BV", "FO", "IO", "LI", "SH", "SM", "IE", "GB", "IE", "GL") 

South_eu<-c("ES","IT", "PT", "MT")

South_east_eu<-c("AL","BA", "CY", "HR", "MK", "RS", "SI", "GR","TR", "YU", "XK")

East_eu<-c( "AM", "BG" , "BY",  "CZ", "EE", "GE", "HU", "LT", "MD", "ME", "PL","RO" , "SK",  "UA", "LV", "CS")

#Central_Asia<-c("AZ", "KG","KZ", "MN", "TJ", "TM", "UZ")

Russia_Central_Asia<-c("RU", "AZ", "KG","KZ", "MN", "TJ", "TM", "UZ", "SU")

Turkey<-c("TR")

West_africa<-c("AO", "BF", "BJ", "CI", "CM", "CV", "GA", "GH", "GM", "GN", "GQ", "GW", "LR", "ML", "MR", "NE", "NG", "SL", "SN", "ST", "TG")

East_africa<-c("KE","ER", "ET", "CM", "BI",  "KM", "MG", "MW", "MZ", "MU", "SC", "RE", "SO", "TZ", "UG", "ZW")

North_africa_Mid_east<-c("EG", "DZ", "AE", "AF", "LY", "BH", "IQ", "IR", "JO", "KW", "LB", "MA", "PS",  "SA", "SD", "SY", "TN", "YE", "IL")

Central_South_africa<-c("CD", "CF", "CG", "RW", "TD", "ZM", "BW", "ZA")

East_asia<-c("CN", "HK", "JP", "KP", "KR", "MO")

South_asia<-c("BD", "IN", "LK", "NP", "PK", "MV")

South_east_asia<-c("BN",  "ID", "KH", "LA", "MY", "PH", "SG", "TH", "TL", "VN")

South_am<-c("AR", "BO", "BR" , "CL", "CO", "EC", "GY", "PE", "PY", "SR", "UY", "VE")

Mex_Central_Carra_am<-c( "GT", "MX","HN" , "NI", "PA", "SV", "CU", "DM", "DO" , "GD", "HT", "JM", "AW", "PR", "AN")

#Carrabean<-c("CU", "DM", "DO" , "GD", "HT", "JM", "AW", "PR")

Anglo_no_eu<-c( "CA", "US", "AU","NZ", "AS")


data$sub_regions<-rep(NA, nrow(data))
data$sub_regions[which(data$citizenship%in%North_West_eu)]<-"North_West_eu"
data$sub_regions[which(data$citizenship%in%East_eu)]<-"East_eu"
data$sub_regions[which(data$citizenship%in%Russia_Central_Asia)]<-"Russia_Central_Asia"
data$sub_regions[which(data$citizenship%in%Turkey)]<-"Turkey"
data$sub_regions[which(data$citizenship%in%West_africa)]<-"West_africa"
data$sub_regions[which(data$citizenship%in%East_africa)]<-"East_africa"
data$sub_regions[which(data$citizenship%in%Central_South_africa)]<-"Central_South_africa"
data$sub_regions[which(data$citizenship%in%North_africa_Mid_east)]<-"North_africa_Mid_east"
data$sub_regions[which(data$citizenship%in%East_asia)]<-"East_asia"
data$sub_regions[which(data$citizenship%in%South_east_asia)]<-"South_east_asia"
data$sub_regions[which(data$citizenship%in%South_am)]<-"South_am"
data$sub_regions[which(data$citizenship%in%Mex_Central_Carra_am)]<-"Mex_Central_Carra_am"
data$sub_regions[which(data$citizenship%in%Anglo_no_eu)]<-"Anglo_no_eu"
data$sub_regions[which(data$citizenship%in%South_eu)]<-"South_eu"
data$sub_regions[which(data$citizenship%in%South_east_eu)]<-"South_east_eu"
data$sub_regions[which(data$citizenship%in%South_asia)]<-"South_asia"


unique(data$citizenship[which(is.na(data$sub_regions)==T)])


table(data$sub_regions, data$VA_easy_1)

#write.table(table(data$sub_regions, data$VA_easy_1), file="table_sub_regions.csv", sep=",")
length(unique(data$sub_regions))


###########

##HOST-YEAR Fixed Effect

data$host_year<-paste(data$cntry, data$year_survey, sep="_")

##A ruler just to count some things:

data$ones<-rep(1, nrow(data))


###Some  stats on the host-year fixed effects

#barplot(sort(tapply(data$ones, data$host_year, sum )), las=2)
mean(tapply(data$ones, data$host_year, sum ))
sd(tapply(data$ones, data$host_year, sum ))
#table(data$VA_easy_1, data$host_year)


#Stats on essround fixed effects
#barplot(tapply(data$ones, data$essround, sum ), las=2)


sum(data$native, na.rm=T)
table(data$VA_easy_1, data$cntry)

#Stats on Enfranchisement
sort(tapply(data$VA_easy_1, data$citizenship, FUN=mean))
sort(tapply(data$VA_easy, data$citizenship, FUN=sd))
mean(data$agea[which(data$native==1 & data$VA_easy_1==1)], na.rm=T)


length(which(data$native==1 & data$VA_easy_1==1))
length(which(data$native==0 & data$VA_easy_1==1))
length(which(data$native==1 & is.na(data$VA_easy_1)==T))
length(which(data$native==1 & is.na(data$VA_easy_1)==F))

